WordPress : How to Register a Widget Area

In your theme functions.php create a function

function cosmowhiz_setup()

inside the function add the following code to register menus as follow:

if ( ! function_exists( 'cosmowhiz_setup' ) ) :
    
    function cosmowhiz_setup() {
    
         register_sidebar( array(
            'name'          => __( 'Sidebar', 'cosmowhiz' ),
            'id'            => 'sidebar-1',
            'description'   => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ),
            'before_widget' => '<section id="%1$s" class="widget %2$s">',
            'after_widget'  => '</section>',
            'before_title'  => '<h2 class="widget-title">',
            'after_title'   => '</h2>',
        ) );
        
        register_sidebar( array(
            'name'          => __( 'Content Bottom 1', 'twentysixteen' ),
            'id'            => 'sidebar-2',
            'description'   => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
            'before_widget' => '<section id="%1$s" class="widget %2$s">',
            'after_widget'  => '</section>',
            'before_title'  => '<h2 class="widget-title">',
            'after_title'   => '</h2>',
        ) );

        register_sidebar( array(
            'name'          => __( 'Content Bottom 2', 'twentysixteen' ),
            'id'            => 'sidebar-3',
            'description'   => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
            'before_widget' => '<section id="%1$s" class="widget %2$s">',
            'after_widget'  => '</section>',
            'before_title'  => '<h2 class="widget-title">',
            'after_title'   => '</h2>',
        ) );
    }
endif; // cosmowhiz_setup

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.