How to create a custom sidebar in WordPress without a plugin.

Steps how to add custom sidebars to your theme without using any plugins.

Step-1 : Register the sidebar

add_action( 'widgets_init', 'wptrinity_custom_sidebar' );
function wptrinity_custom_sidebar() {
    register_sidebar( array(
   'name' => __( 'My Custom wptrinity Sidebar'),
   'id' => 'my-custom-wptrinity-sidebar',
   'description' => __( 'Show widget newsletter' ),
   'before_widget' => '',
   'after_widget' => "",
   'before_title' => '',
   'after_title' => '',
));
}

After added and save the functions.php file you can see them from Appearance -> Widgets.

Step-2 : Add the sidebar into the theme to display it

Now you have to do display the sidebar into your website front-end. To do this add the below code in the sidebar.php file of your active child theme (or theme). This filename maybe changes and depending on it according to your theme called. If you need to display this on another individual page you can add this that your page relevant position.

<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('My Custom Sidebar')) : ?>
			<?php dynamic_sidebar( 'My Custom wptrinity Sidebar' ); ?>
<?php endif; ?>

In the above php code, you must put your sidebar name by replacing the “My Custom wptrinity Sidebar”.

Leave a Comment

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