How to create to sidebar additional for your group of WordPress

Some ago days it appeared in a forum that I frequent the doubt of how to create to sidebar customized for ours theme. Much people can get to think that she is something complicated and end up using plugins as Custom Sidebars, nevertheless WP puts it to us so easy that we can get rid of that load with a few lines of code 😉

If we already learned to create shortcodes in two less than steps, now in only three we will have a new one to sidebar registered and visible in which we will be able to add widgets that we want, as we have done until now with that we have by defect. But first we are going to make clear what is to sidebar.

What is to sidebar and why it serves

If him questions to any person who has used WordPress what is to sidebar most probable are than it responds to you thus: œbecause the column that leaves to the right or left, what is going to be! œ. Although it is not false, he is not absolutely correct. In WP sidebar it is a space in which we will be able to add a series of widgets; although until in the same codex it is defined as œa vertical column does not have because to be thus.

The majority of themes or groups incorporates an only one to sidebar in which to include widgets as which they come from series: recent entrances, recent file, commentaries, cloud of labels, etc. we generally found it to a side of the content in vertical format, nevertheless nothing prevents us to include them in header, footer or where we want.

We will be able to have so many as we want with the method that we are going to see in this article. Why it is going to serve? You will be able to differentiate which to show for the pages of file (search, categories, etc) or the individual article page for example; another example, to use to sidebar concrete with a Call-to-action in a certain page.

The true potential we will find it if we combined it with the customized groups or page templates of our pages (which we will be able to do we ourself).

to 1er step: to register sidebar through functions.php

First that we will make to create it will be to register it through our file functions.php. The ideal will be to make it through ours child theme to avoid future problems to us. If you are using a group first that you will have to do is search within the file that we are going to modify if the call to the function already exists to register_sidebar ().

If the case, you will have to add the code just later, if occurs do not feel to you frees to include it as you want. We will use to register_sidebar () to define the œlateral bar and to assign to him YOU GO only, among others values. The code would be something similar to this:

function to registrar_sidebar () \ {
  to register_sidebar (Array (
   ˜yam™ => ˜Sidebar of example™,
   ˜you go™ => ˜sidebar-example™,
   ˜description™ => ˜Description of example™,
   ˜class™ => ˜to sidebar™,
   ˜before_widget™ => ˜<aside id= " %1$s class= " widget %2$s " >™,
   ˜after_widget™ => ˜</aside>™,
   ˜before_title™ => ˜<h2 class= " widget-title " >™,
   ˜after_title™ => ˜</h2>™,
  ));} add_action (˜widgets_init™, ˜to registrar_sidebar™);

With this first step we will have obtained that seemingly - > Widgets is a new one to sidebar with the title and description that we have defined, verifies that it is thus before happening to the following point. As you also see we will be able to modify other interesting things as headed or the classes that we used, a form to personalize it very simple.

2º step: to create a file sidebar-id.php

WP already is conscious that we have created a new space for our page but still does not know what to do exactly with him. In this step we are going to create a file PHP that will contain the function to dynamic_sidebar () and that will be in charge to call to each one of the widgets active that we have placed through dashboard.

The file at issue we will call it of the same form that YOU GO it that we assigned in the first step. In my case he will be sidebar-ejemplo.php. The code that I will have to insert is the following one:

<? php if (to is_active_sidebar (˜sidebar-example™)): >
         <div id= " widget-area class= " widget-area " >
            <? php to dynamic_sidebar (˜sidebar-example™); >
         </div> <? php endif; >

In the first place which is verified that sidebar it is in use or, is the same, that has some widget active. If it is thus to dynamic_sidebar () it shows of form ordinate widgets that we have placed one by one, but remembers to happen to him to both functions YOU GO of sidebar that we are using.

It remembers: The name of the file must begin by sidebar- so that it is just as YOU GO it that you assigned to him at the time of registering it.

And with this we have finished? Good, we would need to indicate to WordPress where to show it to him. We could copy this code in the place of the group that we want that one visualizes but there is a better form to do it through another function. We see!

to 3er step: how to visualize sidebar that we have created

Finally we will use the function to get_sidebar () to show our new space in the place that we created advisable. If we want that it is in footer we will modify the file footer.php of ours child theme, in the case of using hooks we will use the one that more agrees to us.

We will only have to include this line of code, happening to him the parameter $name that will be equivalent to the file name which we have created. In this case it would be thus:

<? php to get_sidebar (˜example™); >

And thus, we will be able to include it in the part of the group that we want. Ten in account that without the parameter $name will show sidebar to you that it comes by defect, so you do not forget it 😉

Now only it is to add to him some last adjustments by means of CSS and to leave it to your pleasure. A simple tutorial but that will save to you to install some plugin unnecessary; in addition, the satisfaction to do it by one same one also is a point to favor, so you intention to do it!

If you have any doubt, it asks or simply you it has been of utility¦ I invite to you to pass through the commentaries 🙂


  • Om it says:

    Hello in the step number three; where I have it to add if I want it of the left side? Oh how I can move it; it happens that it appears down in the part of siderbar and not as returning a the right. Thanks for your help!

    • Wewokc he says:


      What file you are modifying? Each has its structure and varies according to the group with which you are working.
      For example, if sidebar it appears after œcontent you will have to move the lines that call above when right sidebar of the container.

      If it appears in the part of down is probable that it is because you are modifying footer.php or because it does not have sufficient space to the right and for that reason one lowers automatically. If it is first, the file that you must modify will be page.php, single.php, archive.php or some similar. If it is second, you only must adapt the width by means of CSS.

      If you happen to me a link I throw a look to him! A greeting!

    • Jos© Manuel he says:

      Hello very good explained very good article and. I have one doubts, I have followed all the steps and until there well. But the problem I have it when inserting the third step. I want to put it in the main page and the rest of pages. My subject is twenty-seventeen of wordpress. You could help with that and say me to me where I must place it exactly, in which it divides of the code and in that paginates of the publisher?

      Thanks a greeting.

  • Lorenzo he says:

    hello good, first of all thanks for your help, I have been able to understand everything almost, my problem is when I arrive at the final part, for example I I want to put sidebar over the menu (to header) and that appears to me horrizontal, this is my page as can see I have created two and me gustria that the section of social east in line with the other widget.
    thank you very much.!

    • Wewokc he says:

      Good Lorenzo, the one that you have is plus a problem of HTML and css that another thing. To explain it to you this way would be expensive. I advise you that you dedicate a pair to him of hours to some course online of css, is very simple and it will be able to serve to you to do some minimum modifications in your group without problems.

      Once you are able to show sidebar, as I explain in the article, you will have to give style him to adapt it to the structure of the Web.

      A greeting!

  • Lorenzo he says:

    thank you very much¦!

  • Fernanda it says:

    Hello. My question is that in home or paginates initial of theme of wordpress appear parts as of testimonies, logo of clients etc in the form of slide or something thus, would want to know if this can only be modified, be cleared some and be added others but to pahina from Home.

    • Wewokc he says:

      Hello Fernanda,

      Yes it is possible what you want. It is difficult to be able to help without knowing the group you that you are using but I assure to you that yes it is possible. It is possible that you must touch something of code to be able to do it.

      I invite to you to that here you leave the connection to your page so that can throw a look to him.

      A greeting!

  • Jose he says:

    How it could do this so that it appears to me to sidebar in the categories? Gracias

  • Vintitrenta it says:

    Hello, he is brilliant, but how I do it if I want that this sidebar one only is for the pages of product categories of Woocommerce (the rest of pages I do not want any to sidebar)

It lets a commentary

To subscribe to me!

No, thanks.