• Hi Everyone,

    I am doing some website change on a custom template. A sidebar was originally created to for a number of widgets as seen below. The problem is when I go to the widget area the widgets are there but their is no sidebar to put them in in. When view on the front, there is also no sidebar visible.

    However, if the sidebar.php file is removed then a default sidebar shows on the front but still not in the widget area. I am not sure what is wrong with the code below~:

    if (function_exists('register_sidebar')) {
        	register_sidebar(array(
        		'name' => __('Sidebar Widgets','html5reset' ),
        		'id'   => 'sidebar-widgets',
        		'description'   => __( 'These are widgets for the sidebar.','html5reset' ),
        		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        		'after_widget'  => '</div>',
        		'before_title'  => '<h2>',
        		'after_title'   => '</h2>'
        	));
        	register_sidebar(array(
        		'name' => __('Homepage featured products','html5reset' ),
        		'id'   => 'hp-featured',
        		'description'   => __( 'This widget add featured products to the homepage.','html5reset' ),
        		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        		'after_widget'  => '</div>',
        		'before_title'  => '<h2>',
        		'after_title'   => '</h2>'
        	));
        	register_sidebar(array(
        		'name' => __('Homepage categories links','html5reset' ),
        		'id'   => 'hp-categories-links',
        		'description'   => __( 'This widget add manual links to the homepage in the categories area.','html5reset' ),
        		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        		'after_widget'  => '</div>',
        		'before_title'  => '<h2>',
        		'after_title'   => '</h2>'
        	));
        	register_sidebar(array(
        		'name' => __('Homepage featured pages','html5reset' ),
        		'id'   => 'hp-featured-pages',
        		'description'   => __( 'This widget allows you to control four boxes near the bottom of the homepage.','html5reset' ),
        		'before_widget' => '<li id="%1$s" class="widget %2$s">',
        		'after_widget'  => '</li>',
        		'before_title'  => '<h2>',
        		'after_title'   => '</h2>'
        	));
        	register_sidebar(array(
        		'name' => __('Right Footer Widgets','html5reset' ),
        		'id'   => 'footer-widgets-right',
        		'description'   => __( 'These are widgets for the right-side footer.','html5reset' ),
        		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        		'after_widget'  => '</div>',
        		'before_title'  => '<h2>',
        		'after_title'   => '</h2>'
        	));
        	register_sidebar(array(
        		'name' => __('Left Footer Widgets','html5reset' ),
        		'id'   => 'footer-widgets-left',
        		'description'   => __( 'These are widgets for the left-side footer.','html5reset' ),
        		'before_widget' => '<div id="%1$s" class="widget %2$s">',
        		'after_widget'  => '</div>',
        		'before_title'  => '<h2>',
        		'after_title'   => '</h2>'
        	));
    
        }

    This is the code in the sidebar.php file:

    <div id="sidebar">
    
        <?php dynamic_sidebar('Sidebar Widgets'); ?>
    
    </div>

    Why isn’t it working? I would appreciate any help.

    Thanks.

Viewing 1 replies (of 1 total)
  • The sidebars are not showing because you have not kept the code inside a function and called it with the hooks a good example can be found here
    https://codex.www.ads-software.com/Function_Reference/register_sidebar

    add_action( 'widgets_init', 'theme_slug_widgets_init' );
    function theme_slug_widgets_init() {
        register_sidebar( array(
            'name' => __( 'Main Sidebar', 'theme-slug' ),
            'id' => 'sidebar-1',
            'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ),
            'before_widget' => '<li id="%1$s" class="widget %2$s">',
    	'after_widget'  => '</li>',
    	'before_title'  => '<h2 class="widgettitle">',
    	'after_title'   => '</h2>',
        ) );
    }

Viewing 1 replies (of 1 total)
  • The topic ‘Sidebar is not showing’ is closed to new replies.