To create Custom Sidebar the Sidebar Manager enables you to create a unique sidebar for specific posts, pages, archives and categories. In some cases, a site will feature two sidebars, one on each side of the main content where your posts are found. This tutorial examines some of the information items and features generally found in the sidebar. Usually, before selecting a new theme for our WordPress site, there’s one thing which we always check, which is to check how many sidebars or widget locations are provided by that theme? And where are they all located on the theme layout? Themes which lack sidebars are generally ignored by users. That why you need a theme like TL Corporate Responsive WordPress Theme, which gives you the opportunity to create custom sidebars without any plugin.

Here are all you need to know when creating sidebar for your website. The First thing you need to do is to register your sidebar or widget ready area for your theme. You can register multiple sidebars and widget ready areas. Copy and paste the code below in your theme’s functions.php file, you can locate your site function.php by

  • logging to your wordpress dashboard and at the left menu dropdown click Appearance – Editor – functions.php
  • or if you don’t know how to find your theme files, you’ll find them in your web host in the following directory: www.yoursite.com/wp-content/themes/yourtheme/.

picture1

  • Add this code into functions.php in order to register your custom sidebar:


function tl_widgets_init() {
register_sidebar( array(
'name' => __( 'Main Sidebar', 'tl' ),
'id' => 'sidebar-1',
'description' => __( 'The main sidebar appears on the right on each page except the front page template', 'wpb' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );


register_sidebar( array(
'name' =>__( 'Front page sidebar', 'tl'),
'id' => 'sidebar-2',
'description' => __( 'Appears on the static front page template', 'wpb' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}


add_action( 'widgets_init', 'tl_widgets_init' );

  • Click the “Update file” button when you’re done.

Note that this code we registered two sidebars. We have given them names and descriptions to identify them on Widgets screen. The description parameter can be used to tell users where this sidebar appears in the theme. The wpb is the name of the theme we are working on, it is used here to make these strings translatable. You should replace it with your theme name.

Custom Sidebar

So you just added a dynamic sidebar with the above method, but the sidebars won’t show yet on your websites until they are called in a template like sidebar.php or anywhere else you want to display them. To add these widget areas, edit the template file where you want to display them and paste this code:

With this method you can display any widgets to your website sidebars by just changing the widgets id.

Leave a Reply

Or

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


CAPTCHA Image
Reload Image

Find us on Facebook

Subscribe to our Newsletter