Skip to main content
GeneralWordPressWP Errors

WordPress – id set in the arguments array for sidebar Defaulting to “sidebar-1”

By May 8, 2015One Comment

WordPress logo

Since WordPress updated to 4.2.0, a register_sidebar id error has appeared across several WordPress sites, and is present in some of its most popular themes. Whilst you’re likely only to see this in debug mode, it’s a quick fix and easily remedied.

register_sidebar error

Here’s an example of the WordPress error you might see;

id

was set in the arguments array for the "Blog Sidebar" sidebar. Defaulting to "sidebar-1".

Manually set the id to "sidebar-1" to silence this notice and keep existing sidebar content.

Please see Debugging in WordPress for more information.
(This message was added in version 4.2.0.) in <b>/.../.../.../www/wp-includes/functions.php</b> on line <b>3560</b>

WP codex under WordPress register_sidebar – error explains that;

“If you do not set the id argument value, you will get E_USER_NOTICE messages in debug mode, starting with version 4.2.”

Finding register_sidebar

So how do you fix this? First of all do a search for register_sidebar within your theme folder, it’s most likely to be in the main functions.php file. You’ll likely find a block of code defining your sidebar areas. Below is an example from the popular WordPress theme Salient;

register_sidebar error code

if(function_exists('register_sidebar')) {
register_sidebar(array('name' => 'Blog Sidebar', 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget'  => '</div>', 'before_title'  => '<h4>', 'after_title'   => '</h4>'));
register_sidebar(array('name' => 'Page Sidebar', 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget'  => '</div>', 'before_title'  => '<h4>', 'after_title'   => '</h4>'));
register_sidebar(array('name' => 'WooCommerce Sidebar', 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget'  => '</div>', 'before_title'  => '<h4>', 'after_title'   => '</h4>'));
register_sidebar(array('name' => 'Footer Area 1', 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget'  => '</div>', 'before_title'  => '<h4>', 'after_title'   => '</h4>'));
register_sidebar(array('name' => 'Footer Area 2', 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget'  => '</div>', 'before_title'  => '<h4>', 'after_title'   => '</h4>'));
}

Here’s how the code should have been written, with an id set for each new sidebar.

register_sidebar code fix

if(function_exists('register_sidebar')) {
register_sidebar(array('id' => 'blog-sidebar', 'name' => 'Blog Sidebar', 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget'  => '</div>', 'before_title'  => '<h4>', 'after_title'   => '</h4>'));
register_sidebar(array('id' => 'page-sidebar', 'name' => 'Page Sidebar', 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget'  => '</div>', 'before_title'  => '<h4>', 'after_title'   => '</h4>'));
register_sidebar(array('id' => 'woocommerce-sidebar', 'name' => 'WooCommerce Sidebar', 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget'  => '</div>', 'before_title'  => '<h4>', 'after_title'   => '</h4>'));
register_sidebar(array('id' => 'footer-area-1', 'name' => 'Footer Area 1', 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget'  => '</div>', 'before_title'  => '<h4>', 'after_title'   => '</h4>'));
register_sidebar(array('id' => 'footer-area-2', 'name' => 'Footer Area 2', 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget'  => '</div>', 'before_title'  => '<h4>', 'after_title'   => '</h4>'));
}

Adding an id to each register_sidebar array e.g. ‘id’ => ‘blog-sidebar’, should fix the issue. If using a premium theme, create a support ticket for the change to be added as part of the next update. Otherwise, you can make the change in functions.php of a child theme, so changes to the main theme files don’t wipe out your changes.

Need help – WordPress

If you need help with your WordPress site give us a call or contact us via our Contact form. We’re based off the Essex coast, and are able to offer quick support to many Essex, Norfolk, and London based businesses.

Andrew Taylor

A senior UI designer with over 25 years of web design and web development experience working for some of the largest companies in the UK. An expert in all things Magento and WordPress.

One Comment

Leave a Reply

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