Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP How to Build a WordPress Theme Extending WordPress Template Functionality How to Widgetize a Theme

Paul Neumyer
Paul Neumyer
15,301 Points

Widget Names not showing up

For some reason My Widget names that I am passing into the create_widget function is not showing up. They just say "Sidebar1", "Sidebar 2", and "Sidebar 3". Could it be related to the fact that I have upgraded my local Wordpress site to 3.9.1?

function create_widget($name, $id, $description ){
    $args = array(
        'name'          => __( $name, $name ),
        'id'            => $id,
        'description'   => $description,
        'before_widget' => '',
        'after_widget'  => "",
        'before_title'  => '<h5>',
        'after_title'   => "</h5>\n",
    );

    register_sidebar( '$args');

}


create_widget( 'Left Footer', "footer_left", "Display's in the left bottom of the footer");
create_widget( 'Middle Footer', "middle", "Display's in the middle of the footer");
create_widget( 'Right Footer', "right", "Display's in the right bottom of the footer");

1 Answer

If you mean upgrade from 3.9 to 3.9.1 it's very unlikely. It was maintenance release that doesn't include changes in functionality. And even it was major update WordPress wouldn't significantly change the major functionality such as create_widget function.

Please, try to change your function to:

function create_widget($name, $id, $description ){
    $args = array(
        'name'          => __( $name, 'my_text_domain' ),
        'id'            => $id,
        'description'   => $description,
        'before_widget' => '',
        'after_widget'  => "",
        'before_title'  => '<h5>',
        'after_title'   => "</h5>\n",
    );

    register_sidebar( '$args');

}

or

function create_widget($name, $id, $description ){
    $args = array(
        'name'          => $name,
        'id'            => $id,
        'description'   => $description,
        'before_widget' => '',
        'after_widget'  => "",
        'before_title'  => '<h5>',
        'after_title'   => "</h5>\n",
    );

    register_sidebar( '$args');

}