• Resolved almirdzankovic

    (@almirdzankovic)


    Hi.

    I am creating a child theme to the Storefront theme, and I want to add a new widget area below the Storefront sidebar. I want to do this in my functions.php file, and not overwrite a Storefront theme file.

    I have added this to my functions.php file:

    
    register_sidebar( array( 
    'name' => 'Below Sidebar Custom Techsaker Widget Area', 
    'id' => 'below-sidebar-custom-techsaker-widget-area', 
    'description' => 
    'A below sidebar custom techsaker widget area.', 
    'before_widget' => 
    '<div id="%1$s" class="widget %2$s">', 
    'after_widget' => '</div>', 
    'before_title' => '<h3>', 
    'after_title' => '</h3>' ) );
    
    dynamic_sidebar( 'below-sidebar-custom-techsaker-widget-area' );

    The widget area shows up in the WordPress-admin, but it doesn’t appear on my pages.

    I would greatly appreciate if someone could show me how to do this.

    Thanks.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • But you still need to call the sidebar in the template file of your child theme.
    The register in your functions file simply creates the sidebar.
    The template file will display it.
    i.e.
    https://www.ostraining.com/cdn/images/wordpress/custom-sidebar/2.jpg
    https://www.wpbeginner.com/wp-themes/how-to-add-dynamic-widget-ready-sidebars-in-wordpress/

    Thread Starter almirdzankovic

    (@almirdzankovic)

    Hi.

    Thanks a lot for your reply.

    I ended up doing just that, I now have the following code in my child theme’s function.php:

    register_sidebar( array( 
    'name' => 'Below Sidebar Custom Techsaker Widget Area', 
    'id' => 'below-sidebar-custom-techsaker-widget-area', 
    'description' => 'A below sidebar custom techsaker widget area.', 
    'before_widget' => '<div id="filter_sidebar">', 
    'after_widget' => '</div>', 
    'before_title' => '<h3>', 
    'after_title' => '</h3>' ) );

    And I’ve copied the Storefront sidebar.php to my child theme’s folder and edited to be like this:

    <?php
    /**
     * The sidebar containing the main widget area.
     *
     * @package storefront
     */
    
    if ( ! is_active_sidebar( 'sidebar-1' ) && ! is_active_sidebar( 'below-sidebar-custom-techsaker-widget-area' ) ) {
    	return;
    }
    ?>
    
    <div id="secondary" class="widget-area" role="complementary">
    	<?php 
    	if ( is_active_sidebar( 'sidebar-1' ) ) {
    		dynamic_sidebar( 'sidebar-1' );
    	}
    	 ?>
    	<?php 
    	
    	if ( is_active_sidebar( 'below-sidebar-custom-techsaker-widget-area' ) ) {
    		print("<div id=\"filter_sidebar\">");
    		dynamic_sidebar( 'below-sidebar-custom-techsaker-widget-area' );
    		print("</div>");
    	}
    	
    	 ?>
    </div><!-- #secondary -->

    I just don’t know why the div element with it’s id didn’t appear until I printed it with the sidebar.php file. Anyhow, it works well.

    I’m not an expert at WordPress, but I thought I could use a hook to insert the sidebar; but that is I guess not possible.

    No.
    You needed to added it to the template file.

    The functions file creates the sidebar, the template file displays the sidebar.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How To Add A New Sidebar Widget Area’ is closed to new replies.