How to Register and Show Sidebar in WordPress

Register Sidebar WordPress

wordpress sidebar

Register Sidebar WordPress. wordpress sidebar feature was introduced in wordpress version 2.2. Sidebar is the widget ready area in dashboard where you can add your widget. you can use these sidebar in the anywhere in your wordpress website to show your content.

Sidebar commonly shown on the left side, right side and footer side, but we can show any where according to your need. These Sidebars or widget ready area is available in wordpress Dashboard under Appearance > Widgets. In now these days every theme have 1 or 2 sidebar by default.

In this article i am going to share how you can add sidebar in wordpress theme. register_sidebar() is the function which is used to register a sidebar in the wordpress. Add following code in your functions.php file to register a sidebar.

Register Sidebar

In the above code i have created 2 sidebar left sidebar and right sidebar. register_sidebar() function take array of arguments. Now i am going to share you regarding these arguments.

  • name: This is the name of your sidebar which is shown in the wordpress dashboard. you can give any name to your sidebar like i have give the name left sidebar and right sidebar.
  • id: This is the Sidebar Id. id contain only lowercase letters with no space. from wordpress version 4.2 if you not give any id it will give you a E_USER_NOTICE warning.
  • description: This is the description regarding your sidebar. this description is only visible in the wordpress admin are. you can add any type of help text in description area.
  • class: using this argument you can add class, but this class is only visible in the wordpress dashboard not in frontend.
  • before_widget: Using the argument you can add your html tag which placed before every widget. default it contain li tag.
  • after_widget: This contain the closing html tag which placed after every widget by default it contain closing li tag.
  • before_title: This contain your html which is place before any widget title by default it contain h2 tag with class widgettitle
  • after_title: This contain your closing html tag after widget title by default it contain closing h2 tag.

Displaying a Dynamic Sidebar in WordPress

After creating sidebar now it’s time to show that sidebar in your wordpress theme. so now dynamic_sidebar() is the function which is used to show the sidebar in frontend of your wordpress website, this function contain id of the sidebar as the argument.

Add the following code where you want to show the sidebar in the frontend.

Sandeep Kumar

Sandeep kumar is a web developer and a professinal blogger. He works for latest technologies and write articles what he learn. In ICodeHub he share web languages tutorials and other programming tips and tricks. if you need some help or have some suggestion then mail him at sandeep92pal@gmail.com without any hesitation. He believes in learning and sharing.