WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] TwentyTen child theme - adding widget areas via child's functions.php (5 posts)

  1. jeobrussels
    Member
    Posted 3 years ago #

    Dear all, I am still struggling with the functions.php of my child theme...
    I am trying to override the widget call and add two more widget areas to my child thme via the functions.php. What is wrong with the following code (it just produces a blank output if added to the existing code in the - working - child theme functions.php)? http://wordpress.pastebin.com/NQUD9FSk

  2. jeobrussels
    Member
    Posted 3 years ago #

    OK; solved. The code to add must look something like that:

    add_action( 'init', 'header_widgets_init' );
    function header_widgets_init() {
    	// Area 7, located in the header. Empty by default.
    	register_sidebar( array(
    		'name' => __( 'First Header Widget Area', 'twentyten' ),
    		'id' => 'first-header-widget-area',
    		'description' => __( 'The first header widget area', 'twentyten' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );	
    
    	// Area 8, located in the header. Empty by default.
    	register_sidebar( array(
    		'name' => __( 'Second Header Widget Area', 'twentyten' ),
    		'id' => 'second-header-widget-area',
    		'description' => __( 'The second header widget area', 'twentyten' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );	
    
    }
  3. nomolos
    Member
    Posted 3 years ago #

    Hello I tried to follow your code to get the "above header" to work but no luck. Could you possibly post all the needed code and where each doc needs changing. Thank you so muc

    OR. If anyone else has the answer please let me know with full code changes .

  4. jocken
    Member
    Posted 3 years ago #

    If your theme already supports sidebars (like twentyten and it's child themes). You can just add:

    register_sidebar( array(
    		'name' => __( 'First Header Widget Area', 'twentyten' ),
    		'id' => 'first-header-widget-area',
    		'description' => __( 'The first header widget area', 'twentyten' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );	
    
    	// Area 8, located in the header. Empty by default.
    	register_sidebar( array(
    		'name' => __( 'Second Header Widget Area', 'twentyten' ),
    		'id' => 'second-header-widget-area',
    		'description' => __( 'The second header widget area', 'twentyten' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );

    Without action and function.

    But if you know would like to with an action, you could write:

    add_action( 'widgets_init', 'header_widgets_init', 11);

  5. nomolos
    Member
    Posted 3 years ago #

    Thank you so much for your prompt reply.
    I have pasted code in functions php but have this error above header:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'header_widgets_init' not found or invalid function name in /Applications/xampp/xamppfiles/htdocs/wordpress/wp-includes/plugin.php on line 395

    Line 395 is:

    call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));

    I am not capable enough with php to understand what now must be changed. Is "header_widgets_init" not an accepted arg and if so where can I change the args to make it work.

    Sorry for being so dumb but thank you so much for your really rapid reply.

Topic Closed

This topic has been closed to new replies.

About this Topic