How to create sidebars on WordPress that simply works

How to create sidebars on WordPress that simply works

You can create your own sidebar on wordpress very easily.

Just add this to your functions.php:

// Register custom sidebar
function register_custom_sidebar() {
	$args = array(
		'id'            => 'my-custom-sidebar',
		'name'          => __( 'Custom Sidebar'),
	register_sidebar( $args );
add_action( 'wp_loaded', 'register_custom_sidebar');

If you’re a real smartass you noticed we used wp_loaded instead of widgets_init.

Well, that’s intentional.

We do so to avoid messing all our previous existing sidebars. Widgets are assigned to sidebars not by their ID, but by their registration order – by adding our sidebar with wp_loaded, we make sure our sidebar is registered last, so it doesn’t interfere with the order or previous sidebars.


Register Sidebar WordPress

Now we can add widgets to our custom sidebar.


To show our custom sidebar in our theme, we just have to add this piece of code to our theme files:

	<?php dynamic_sidebar('my-custom-sidebar'); ?>

There you have it! Your custom sidebar for WordPress! Easy, right?

Method 2:

  • Duplicate your sidebar.php
  • Rename it sidebar-custom.php
  • Make your changes and call it via dynamic_sidebar, as above

Tag: ,