Widgets are such an important part of WordPress themes and hence this post is for the users who want to add widget ready area in WordPress themes. Firstly, you need to register your custom widget ready area for your theme. Paste the following code inside theme’s functions.php file.

Please note that you can also register multiple custom widget areas.

// Register Sidebars
function custom_sidebars() {

$args = array(
'id' => 'custom_sidebar',
'name' => __( 'Custom Widget Area', 'text_domain' ),
'description' => __( 'A custom widget area', 'text_domain' ),
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
);
register_sidebar( $args );

}
add_action( 'widgets_init', 'custom_sidebars' );

Here In the above code, we have registered a sidebar and given it a name and description to recognize them on widget screen.

custom widget area

We have just registered dynamic sidebar. You can now add widgets to the sidebar by heading towards dashboard >> Appearance >> Widgets. However, this sidebar will not appear on site they are called in a template file like sidebar.php, footer.php or anywhere else you want to show them. To add this custom widget area, edit the template file where you want to display it and paste the following code:

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('custom_sidebar') ) : ?>
<!–Default sidebar info goes here–>
<?php endif; ?>

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Beat the Clock Sale! ⏰⏳🌞 - Get 15% off on all plugins & themes.
Coupon : CLOCK15