• Resolved tabatha.j22

    (@tabathaj22)


    Greetings,

    I am trying to add a new sidebar location inside the container. I tried various ways that were shown on your forum.

    This is what I have in the functions file…

    function my_inside_container_widgets_init() {
    
    	register_sidebar( array(
    		'name'          => 'Inside Container Sidebar',
    		'id'            => 'inside-container-sidebar',
    		'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => apply_filters( 'generate_start_widget_title', '<h4 class="widget-title">'),
    		'after_title'   => apply_filters( 'generate_end_widget_title', '</h4>' ),
    	) );
    
    }
    
    add_action('widgets_init','my_inside_container_widgets_init');

    I’m struggling with the other steps from your forum to add this new sidebar. It was over a month ago since I tried it last so my memory of what I tried are sketchy and I have no idea what happened to my notes.

    I would greatly appreciate your help.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there,

    That code is just for registering the widget area.

    You need to place a dynamic_sidebar( 'inside-container-sidebar' ); to your target area for the actual sidebar location to show up on the front-end.

    If you’re trying to add this on a container block inside a content, you may have to wrap the mentioned function to a helper shortcode.

    Example:

    add_shortcode('inside_container_sidebar',function(){
        ob_start();
        // Start your PHP below
        dynamic_sidebar( 'inside-container-sidebar' );
        // End your PHP above
        return ob_get_clean();
    });

    You then place [inside_container_sidebar] shortcode on a shortcode block inside a container block of your choosing. ??

    Thread Starter tabatha.j22

    (@tabathaj22)

    Thank you for the quick response.

    I did this and it seems to work…

    <?php
    /**
     * GeneratePress child theme functions and definitions.
     *
     * Add your custom PHP in this file. 
     * Only edit this file if you have direct access to it on your server (to fix errors if they happen).
     */
     
     function my_inside_container_widgets_init() {
    
    	register_sidebar( array(
    		'name'          => 'Inside Container Sidebar',
    		'id'            => 'inside-container-sidebar',
    		'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => apply_filters( 'generate_start_widget_title', '<h4 class="widget-title">'),
    		'after_title'   => apply_filters( 'generate_end_widget_title', '</h4>' ),
    	) );
    }
    add_action('widgets_init','my_inside_container_widgets_init');
    
    add_action( 'generate_inside_container', function() {
    dynamic_sidebar( 'inside-container-sidebar' );
    } );
    

    Is that what you said to do?

    Also, thank you for showing me the shortcode option. That’s pretty cool and I may use that in the future for something else.

    I greatly appreciate your help. Thanks!

    I see you’re using add_action. That’s actually preferrable over making a shortcode.

    I only suggested it because I thought you wanted to add it witihn the content which has no hooks. ??

    But if generate_inside_container is what you meant it to be added on then that’s perfect. ??

    Thread Starter tabatha.j22

    (@tabathaj22)

    I hope you are doing well. I really appreciate you helping me with this. Everything is working perfectly.

    Thank you very much!

    Nice one. No problem. Glad you got it sorted. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add new sidebar location’ is closed to new replies.