How to make custom Sidebars in a WordPress Theme

FerdieQO

Well-known member
Joined
Jul 15, 2016
Messages
213
Points
28
I have a page using default sidebar from WordPress but I would create the second sidebar and add any custom blocks into this sidebar.
Does any one know and giving a guide?
 

Alex_smith

Well-known member
Registered
Joined
Dec 19, 2012
Messages
90
Points
0
You can follow these steps to add a custom side to any wordpress themes

go to your theme folder, find functions.php and adding as follows

Code:
if ( function_exists('register_sidebar') ) {
	register_sidebar(array(
		'name' => 'Custom Sidebar',
		'id' => 'custom-sidebar',
		'description' => 'Sidebar below Header image',
		'before_widget' => '<li id="%1$s">',
		'after_widget' => '</li>',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	));
}
How to show this sidebar on your theme, find in your theme, there a defautl WP sidebar like this

Code:
<?php get_sidebar(); ?>
Deactivate it by adding comment // before the code

Code:
<?php //get_sidebar(); ?>
add above

Code:
<div id="custom-sidebar">
   <ul>
      <?php
      if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('custom-sidebar') ) :
      endif; ?>
   </ul>
   <div style="clear:both"></div>
</div>
Now go to your widget, a custom sidebar will appear there like this

custome-sidebar.png

and adding available widgets to your custom sidebar.

available-widgets.png


Hope that helps!
 
Recommended Threads
Replies
16
Views
4,773
Replies
8
Views
4,583

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top