Support » Theme: Toolbox » Adding Widgets to Toolbox Theme as a child Theme

  • Hi, hope that someone can give me a hint on how can i add more widgets to a child function.php file?

    I used the following code, this works on the parent theme but not in the child theme.

    <?php
      function sandbox_widgets_init() {
         if ( !function_exists('register_sidebars') )
    	return;
    
          if ( function_exists('register_sidebar') )
    	register_sidebar(array(
    		'name' => 'Home Module A',
    		'before_widget' => '<div align="center">',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2 class="txtalt">',
    		'after_title'   => '</h2>',
    	));
    }
    ?>

    Thanks in advance for your effort and time.

Viewing 11 replies - 1 through 11 (of 11 total)
  • <?php
    
    function mytheme_widgets_init() {
    	register_sidebar( array(
    		'name' => 'Home Module A',
    		'before_widget' => '<div align="center">',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2 class="txtalt">',
    		'after_title'   => '</h2>',
    	) );
    }
    add_action( 'widgets_init', 'mytheme_widgets_init' );
    

    Also please note that you should be using valid HTML. 🙂 The align attribute is long deprecated, use CSS instead.

    Thread Starter Moraima R.

    (@mripz)

    Hey hi, thank you for your response and advice, I will review my html code. But this option unfortunately still not working.

    I’m using the toolbox theme as a parent and using toolbox-child theme, and still can not get it to work, I can not see a way to add custom widgets to this child theme, without modifying the parent theme.

    Thanks in advance.

    Try this:

    <?php
    
    function mytheme_widgets_init() {
    	register_sidebar( array(
    		'name' => __( 'Home Module A', 'toolbox' ),
    		'id' => 'sidebar-3',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget' => "</aside>",
    		'before_title' => '<h1 class="widget-title">',
    		'after_title' => '</h1>',
    	) );
    }
    add_action( 'widgets_init', 'mytheme_widgets_init' );
    

    My example was missing the “id” node in the array.

    Thread Starter Moraima R.

    (@mripz)

    Thank you very much Lance, but the only way that is working, is adding this to the parent function.php, i was unable get running this code on the child theme.

    Sounds to me like you have something broken elsewhere in your child theme. Try deleting everything in your child functions.php and add back in just one function at a time.

    Then you can see what’s causing a conflict.

    I have the code above working in a sample Toolbox child theme.

    Thread Starter Moraima R.

    (@mripz)

    My toolbox child theme function.php is blank, and the only code is the one you gave to me, i don’t know why is not working.

    I’m having a similar problem with the “powered-by” Theme. I’m starting with a blank functions.php, and adding the function mytheme_widgets_init. The parent’s functions theme has not been altered at all.

    My child theme’s functions.php looks like this:

    <?php
    function mytheme_widgets_init() {
    	register_sidebar(array(
    		'name' => 'Footer',
    		'before_widget' => '<div class="footer-item">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3>',
    		'after_title' => '</h3>',
    	));
    }
    	add_action( 'widgets_init', 'mytheme_widgets_init' );
    
    ?>

    Edit: got the above code working, but only within the parent theme’s functions.php. Adding it to the child theme’s functions.php does nothing.

    Any thoughts?

    @smerdyakov Try adding in the “id” node to the array.

    Also, make sure you have the latest Toolbox code from http://wordpress.org/extend/themes/toolbox.

    Voila! It works! Thanks Lance.

    One more (edit: two more!) quick question(s) ; )

    In the widget admin area, my new “footer” sidebar is now at the top of the list. Is there any way to have it appear below my other “regular” sidebars?

    And also, why do I have to use the ID? I’ve seen other examples that leave it out. I’m not put off, just curious : )

    After looking at this some more, it’d probably be better to use the same action hook as the parent theme. I forgot that Toolbox uses “init” instead of “widgets_init”.

    add_action( 'init', 'mytheme_widgets_init' ); instead of add_action( 'widgets_init', 'mytheme_widgets_init' );

    That means the Toolbox sidebars will be show up first in the sidebar list, and leaving off the ID should work, too.

    Hi Lance, thanks for sticking with me!

    Unfortunately, my widget disappears if I remove the ID.

    The working code, as is:

    function powered_bot_widgets_init() {
    	// Powered-Bot Sidebar
    	register_sidebar( array(
    	'name' => 'Footer',
    	'id' => 'sidebar-4',
    	'before_widget' => '<div class="footer-item">',
    	'after_widget' => '</div>',
    	'before_title' => '<h3>',
    	'after_title' => '</h3>',
    	) );
    }
    
    add_action( 'init', 'powered_bot_widgets_init' );
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Adding Widgets to Toolbox Theme as a child Theme’ is closed to new replies.