WordPress WordPress Theme Development Finishing Your WordPress Theme Adding Widget Areas to a WordPress Theme

Sidebar only shows up on Blog page

For some reason, my Sidebar only appears on the Blog page. I ran all my code through HTML and PHP validators, but was unable to figure out what I'm doing wrong.

The PHP validator gave me the following error message: "Sidebars need to be registered in a custom function hooked to the widgets_init action. See: register_sidebar()."

Can anyone give me advice as to what specific PHP files I should be focusing on, to correct the issue?

Thanks in advance.

2 Answers

Paulius Vitkus
Paulius Vitkus
24,230 Points

Could you paste your register_sidebar() code there? According to error, there is something wrong with sidebar registering.

Paulius, here is my code for register_sidebar():

function wpt_create_widget( $name, $id, $description ) {

        'name' => __( $name ),   
        'id' => $id, 
        'description' => __( $description ),
        'before_widget' => '<div class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<h2 class="module-heading">',
        'after_title' => '</h2>'


wpt_create_widget( 'Page Sidebar', 'page', 'Displays on the side of pages with a sidebar' );
wpt_create_widget( 'Blog Sidebar', 'blog', 'Displays on the side of pages in the blog section' );

In my case, the Sidebar appeared at the very bottom of the "uncategorized" page. I had to add a missing closing tag </div> after "?php get_sidebar(); ?" on line 47 (archive.php file) in order for the Sidebar to show up properly on that page. Try and see if it helps you as well.

Victoria, thanks for your response. I checked my archive.php file, and I do seem to have a closing tag after "?php get_sidebar(); ?" on line 47. So, there must be something else that I am overlooking. I will have to go through my code again and see what else might be amiss.