Create a Header Widget area without messing with functions.php file.

I gave up on the gallery theme and switched to the network theme because it is easier to display all posts featured images on main blog front page. My question is how do I add a header widget area without needing to alter the main functions.php file.

The only way I could do it as of now is to remove the following code:

/* Register the widget columns */
function network_widgets_init() {
	global $themename, $shortname, $options, $options2, $options3, $bp_existed, $multi_site_on;
register_sidebar(
	array(
		'name'          => __( 'Footer', 'network' ),
		'id'            => 'footer-page',
		'description'   => 'Footer',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>'
	)
);
register_sidebar(
	array(
		'name'          => __( 'Sidebar Blog', 'network' ),
		'id'            => 'sidebar-blog',
		'description'   => 'Blog',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>'
	)
);
if($bp_existed == 'true') {
register_sidebar(
	array(
		'name'          => __( 'BuddyPress Pages', 'network' ),
		'id'            => 'sidebar-members',
		'description'   => 'BuddyPress pages',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>'
	)
);
}
}
add_action( 'widgets_init', 'network_widgets_init' );

and put it in the child functions.php file as such:

/* Register the widget columns */
function network_widgets_init() {
	global $themename, $shortname, $options, $options2, $options3, $bp_existed, $multi_site_on;
register_sidebar(
	array(
		'name'          => __( 'Header Widget', 'network' ),
		'id'            => 'home',
		'description'   => 'Header',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>'
	)
);
register_sidebar(
	array(
		'name'          => __( 'Footer', 'network' ),
		'id'            => 'footer-page',
		'description'   => 'Footer',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>'
	)
);
register_sidebar(
	array(
		'name'          => __( 'Sidebar Blog', 'network' ),
		'id'            => 'sidebar-blog',
		'description'   => 'Blog',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>'
	)
);
if($bp_existed == 'true') {
register_sidebar(
	array(
		'name'          => __( 'BuddyPress Pages', 'network' ),
		'id'            => 'sidebar-members',
		'description'   => 'BuddyPress pages',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>'
	)
);
}
}
add_action( 'widgets_init', 'network_widgets_init' );

See how I added the header widget code at the beginning? I then put the following call to the widget area in the home.php file as such:

<?php get_header() ?>
	<div id="content"><!-- start #content -->
		<div class="padder">

<!-- Begin of Header Widget Area -->
	<center><table style="width:750px"><tbody><tr><td><?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Header Widget') ) : ?>
	<?php endif; ?></td></tr></tbody></table></center>
       <!-- End Header Widget Area -->

	       <?php locate_template( array( '/library/components/feature-content.php' ), true ); ?>
       </div>
	</div><!-- end #content -->
<?php get_footer() ?>

The part I added is in between the <!-- Begin of Header Widget Area --> and <!-- End Header Widget Area --> It works just fine but I know on the next theme upgrade all will be lost and I'll have to do it again. Not a big deal but if I can prevent it I would like to know how I can have it only use the one in the child functions.php file and ignore the one in the parent functions.php file. Or if I have to change the above code how do I go about doing it?

Plus if the author can redesign the theme to include a header widget area that would be perfect.

The part I wouldn't know how to do is what would I change `function network_widgets_init() {
global $themename, $shortname, $options, $options2, $options3, $bp_existed, $multi_site_on;andadd_action( 'widgets_init', 'network_widgets_init' );` to?

Thanks for helping with all my questions.
John

  • johnzena
    • Design Lord, Child of Thor

    The last paragraph should read:
    The part I wouldn't know how to do is what would I change

    function network_widgets_init() {
    	global $themename, $shortname, $options, $options2, $options3, $bp_existed, $multi_site_on;	<code>and</code>add_action( 'widgets_init', 'network_widgets_init' );

    to?

    Thanks again;
    John

  • johnzena
    • Design Lord, Child of Thor

    That example is doing what I don't want it to do. In step one it says register your widget areas in your functions.php file by adding them beneath the widget areas that are already there. So what is the difference between what they did and I did. We both edited the functions.php file. That is what I was trying to avoid. Is there anyway to not have to go in to the functions.php file?

  • johnzena
    • Design Lord, Child of Thor

    Okay I got it to work, all I had to do was put this part of the code:

    <?php
    
    register_sidebar(
    	array(
    		'name'          => __( 'Header Widget', 'network' ),
    		'id'            => 'home',
    		'description'   => 'Header',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h4 class="widgettitle">',
            'after_title' => '</h4>'
    	)
    );	
    
    ?>

    in the child functions.php file. What confused me is everybody says on all the help sites I've come across (including the tutorial on this site) that you have to put it below the other ones. I guess not. I wish the tutorial would have said put the codes for sidebar 1 & 2 in the child functions.php file surround by the <php? ?> tags. I wish I would have done this yesterday from the start. Funny how things you think shouldn't work do. Please add what I found out to the above tutorials page.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.