I want to register a sidebar but I am a little confused about the uses of the id argument in register_sidebar function.
Codex says: id – Sidebar id – Must be all in lowercase, with no spaces
(default is a numeric auto-incremented ID).
Of what use is the id argument and must it always be in numeric form?.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The sidebar ID is used to uniquely identify this specific sidebar. If you don’t set it and something creates another, you could find that your sidebar moves somewhere unexpected!
It doesn’t need to be numeric – you can use strings, too.
Method 2
John Landells’ answer is good and correct.
I want to add a List of forbidden or reserved IDs – these IDs may appear on the widget config page /wp-admin/widgets.php. If you use one of these … strange things will happen due to duplicated IDs. Drag and drop will probably not work anymore. See Ticket #14466 for the most obvious case: #footer.
Update, Sept. 17.: #footer will be allowed in WP 3.5.
Update, Nov., 06.: Per ticket 14466 all widget IDs in widgets.php are prefixed with sidebar- now. The following list will be obsolete with WordPress 3.5. Probably.
Also, an ID should not start with a number, that’s invalid HTML.
Installed plugins affecting this list: Debug Bar, Debug Bar Cron, Monster Widget.
#_wpnonce_widgets
#ab-awaiting-mod
#access-off
#access-on
#adminmenu
#adminmenuback
#adminmenushadow
#adminmenuwrap
#adv-settings
#available-widgets
#collapse-button
#collapse-menu
#colors-css
#contextual-help-back
#contextual-help-columns
#contextual-help-link
#contextual-help-link-wrap
#contextual-help-wrap
#debug-bar-actions
#debug-bar-cron
#debug-bar-css
#debug-bar-info
#debug-bar-menu
#debug-bar-wp-query
#debug-menu-link-Debug_Bar_Object_Cache
#debug-menu-link-Debug_Bar_Queries
#debug-menu-link-Debug_Bar_WP_Query
#debug-menu-link-ZT_Debug_Bar_Cron
#debug-menu-links
#debug-menu-target-Debug_Bar_Object_Cache
#debug-menu-target-Debug_Bar_Queries
#debug-menu-target-Debug_Bar_WP_Query
#debug-menu-target-ZT_Debug_Bar_Cron
#debug-menu-targets
#debug-status
#debug-status-db
#debug-status-memory
#debug-status-php
#debug-status-site
#footer
#footer-left
#footer-thankyou
#footer-upgrade
#icon-themes
#menu-appearance
#menu-comments
#menu-dashboard
#menu-links
#menu-media
#menu-pages
#menu-plugins
#menu-posts
#menu-posts-domicile
#menu-settings
#menu-tools
#menu-users
#object-cache-stats
#querylist
#removing-widget
#rss-items-2
#rss-items-__i__
#rss-show-author-2
#rss-show-author-__i__
#rss-show-date-2
#rss-show-date-__i__
#rss-show-summary-2
#rss-show-summary-__i__
#rss-title-2
#rss-title-__i__
#rss-url-2
#rss-url-__i__
#screen-meta
#screen-meta-links
#screen-options-link-wrap
#screen-options-wrap
#screenoptionnonce
#show-settings-link
#tab-link-missing-widgets
#tab-link-overview
#tab-link-removing-reusing
#tab-panel-missing-widgets
#tab-panel-overview
#tab-panel-removing-reusing
#widget-10_recent-posts-__i__
#widget-11_rss-__i__
#widget-12_search-__i__
#widget-13_tag_cloud-__i__
#widget-14_text-__i__
#widget-15_widget_twentyeleven_ephemera-__i__
#widget-16_rss-2
#widget-1_archives-__i__
#widget-2_calendar-__i__
#widget-3_categories-__i__
#widget-4_nav_menu-__i__
#widget-5_links-__i__
#widget-6_meta-__i__
#widget-7_monster-__i__
#widget-8_pages-__i__
#widget-9_recent-comments-__i__
#widget-archives-__i__-count
#widget-archives-__i__-dropdown
#widget-archives-__i__-savewidget
#widget-archives-__i__-title
#widget-calendar-__i__-savewidget
#widget-calendar-__i__-title
#widget-categories-__i__-count
#widget-categories-__i__-dropdown
#widget-categories-__i__-hierarchical
#widget-categories-__i__-savewidget
#widget-categories-__i__-title
#widget-links-__i__-category
#widget-links-__i__-description
#widget-links-__i__-images
#widget-links-__i__-limit
#widget-links-__i__-name
#widget-links-__i__-orderby
#widget-links-__i__-rating
#widget-links-__i__-savewidget
#widget-list
#widget-meta-__i__-savewidget
#widget-meta-__i__-title
#widget-monster-__i__-savewidget
#widget-nav_menu-__i__-nav_menu
#widget-nav_menu-__i__-savewidget
#widget-nav_menu-__i__-title
#widget-pages-__i__-exclude
#widget-pages-__i__-savewidget
#widget-pages-__i__-sortby
#widget-pages-__i__-title
#widget-recent-comments-__i__-number
#widget-recent-comments-__i__-savewidget
#widget-recent-comments-__i__-title
#widget-recent-posts-__i__-number
#widget-recent-posts-__i__-savewidget
#widget-recent-posts-__i__-title
#widget-rss-2-savewidget
#widget-rss-__i__-savewidget
#widget-search-__i__-savewidget
#widget-search-__i__-title
#widget-tag_cloud-__i__-savewidget
#widget-tag_cloud-__i__-taxonomy
#widget-tag_cloud-__i__-title
#widget-text-__i__-filter
#widget-text-__i__-savewidget
#widget-text-__i__-text
#widget-text-__i__-title
#widget-widget_twentyeleven_ephemera-__i__-number
#widget-widget_twentyeleven_ephemera-__i__-savewidget
#widget-widget_twentyeleven_ephemera-__i__-title
#widgets-left
#widgets-right
#wp-admin-bar-a8c_developer
#wp-admin-bar-comments
#wp-admin-bar-debug-bar
#wp-admin-bar-edit-profile
#wp-admin-bar-logout
#wp-admin-bar-my-account
#wp-admin-bar-new-content
#wp-admin-bar-new-content-default
#wp-admin-bar-new-domicile
#wp-admin-bar-new-link
#wp-admin-bar-new-media
#wp-admin-bar-new-page
#wp-admin-bar-new-post
#wp-admin-bar-new-user
#wp-admin-bar-root-default
#wp-admin-bar-site-name
#wp-admin-bar-site-name-default
#wp-admin-bar-top-secondary
#wp-admin-bar-updates
#wp-admin-bar-user-actions
#wp-admin-bar-user-info
#wp-admin-bar-view-site
#wp_inactive_widgets
#wpadminbar
#wpbody
#wpbody-content
#wpcontent
#wpwrap
#zt-debug-bar-cron-css
I collected the IDs with a small plugin that can be used on any page:
<?php # -*- coding: utf-8 -*-
/* Plugin Name: T5 List IDs */
add_action( 'shutdown', function()
{ ?>
<script>
jQuery( function( $ )
{
var els = []
$( '[id]' ).each( function() { els.push( this.id ) } )
els.sort()
var pre = $( '<pre/>' ).css( 'margin','10px' ).html( '#'+els.join( '<br>#' ) )
$( document.documentElement ).append( pre )
})
</script><?php
}
);
Method 3
You have to avoid multiple - characters, like test1---test2
Method 4
Apparently, you have to avoid IDs that include prefixes from the above list as well:
e.g.:
#footer-xxx #footer-yyy
The following setup initially worked, but resulted in errors (using the monsoon theme):
register_sidebar( array(
'name' => esc_html__( 'Footer Area', 'monsoon' ),
'id' => 'footer-area',
'description' => esc_html__( 'Appears above the footer.', 'monsoon' ),
'before_widget' => '<div class="col-sm-3 footer-area widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
) );
By renaming the sidebar, the errors disappeared. I haven’t tested on other themes, though. So this might only be applicable to my setup.
However, thus thread really helped me in my search for a solution 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0