• Hello,

    I made a child theme and uploaded file functions.php which has just <?php in it…

    I pasted this code under it becouse I want a widget in the header :

    // Adds a widget area.
    if (function_exists(‘register_sidebar’)) {
    register_sidebar(array(
    ‘name’ => ‘Extra Header Widget Area’,
    ‘id’ => ‘extra-widget-area’,
    ‘description’ => ‘Extra widget area after the header’,
    ‘before_widget’ => ‘<div class=”widget my-extra-widget”>’,
    ‘after_widget’ => ‘</div>’,
    ‘before_title’ => ‘<h2>’,
    ‘after_title’ => ‘</h2>’
    ));
    }

    // Place the widget area after the header
    add_action (‘__after_header’, ‘add_my_widget_area’, 0);
    function add_my_widget_area() {
    if (function_exists(‘dynamic_sidebar’)) {
    dynamic_sidebar(‘Extra Header Widget Area’);
    }
    }

    I worked with notepad and nothing happens when I upload this code… I do not see a new widget in appearance-widgets…

    What am I doing wrong?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Don’t you see a new widget area named “Extra Header Widget Area” in your Appearance -> Widgets ?

    Thread Starter dt125x

    (@dt125x)

    No, it’s not …

    Is it maybe problem in plugin “child themify” for making child theme?
    It made style.css like it should and than I copied function.php from original theme and erased it all… Just added <?php and thats it…

    I think I am doing it all ok…

    Help?

    Thread Starter dt125x

    (@dt125x)

    Ok I solved it… Problem is because I copied functions.php from original and just erased text from it… Now I made completly new document in notepad and it works…

    Thanks for help 😉

    So you copied functions.php in your child theme, and now it looks like this:

    <?php
    // Adds a widget area.
    if (function_exists('register_sidebar')) {
    register_sidebar(array(
    'name' => 'Extra Header Widget Area',
    'id' => 'extra-widget-area',
    'description' => 'Extra widget area after the header',
    'before_widget' => '<div class="widget my-extra-widget">',
    'after_widget' => '</div>',
    'before_title' => '<h2>',
    'after_title' => '</h2>'
    ));
    }
    
    // Place the widget area after the header
    add_action ('__after_header', 'add_my_widget_area', 0);
    function add_my_widget_area() {
    if (function_exists('dynamic_sidebar')) {
    dynamic_sidebar('Extra Header Widget Area');
    }
    }

    right?
    That should work! But, I know it could be a silly question … have you activated your child theme? I mean in Appearence -> Themes ?
    Consider that to see that area in Appearance widgets, the only relevant part is that under //Adds a widget area.
    The other one is meant to “add” the widgets you put in that area to the pages after the header.
    Could you provide a link to your site? Just to see if your child-theme is loaded.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to work with function.php in child theme ?’ is closed to new replies.