1

I'm new to wordpress and it's difficult for me to find some basic information in forums and documentation.

I'm trying to create my own widget areas, and place my widgets there in administration panel. But I cannot find some instructions of how to do that.

For now, there is only one widget area in the template I'm using as a base called "Sidebar 1". I'd like to add more areas like this one. Can you give me some guidelines or post some useful links please?

0

You can create new sidebar areas by adding the following code to your theme's functions.php

register_sidebar( array(
    'name'          => __( 'Content Sidebar', 'mytheme' ),
    'id'            => 'sidebar-2',
    'description'   => __( 'Sidebar description', 'mytheme' ),
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget'  => '</aside>',
    'before_title'  => '<h3 class="widget-title">',
    'after_title'   => '</h3>',
) );

You can change the HTML structure to match your other sidebar and make sure your ID is something unique. Once this has been added you will see a new sidebar under widgets in the admin.

Then to display all you need to do is add:

<?php 
if ( is_active_sidebar( 'sidebar-2' ) ) : 
    dynamic_sidebar( 'sidebar-2' ); 
endif; ?>

To wherever you want the new sidebar to display (usually sidebar.php) making sure the ID's match.

More information about Sidebars can be found here: https://codex.wordpress.org/Sidebars

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.