featured-large-adding-widgets

Widgets are great. They let you put all sorts of stuff around your main content.

The only limitations with widgets is that your theme controls where they go. If you want a widget where your theme hasn’t placed one, then you’re out of luck.

In this post we’ll go over how to put your own new widgets wherever you like.

As this process requires changing a number of template themes, it’s advisable to create a child theme and work with that.

 

Add Code to Functions File

The first thing you’ll need to do is add some code to your functions file. (Appearance > Editor > Theme Functions – functions.php)

Place the following at the bottom of that file:

 

 

 

We’ll go over that code. You’ll need to change some of it to suit your own purposes.

 

The first thing to pay attention to is this line:

 

That’s the unique ID (my-new-widget) that you want to give your widget area. You can make it whatever you like, but make sure it’s unique so that it doesn’t conflict with other widget areas.

If you want to create a second widget, it will need to have a different ID.

 

The next line to look at is this one:

 

This is where you give your widget area a name that will show up on your widgets page.

The “text_domain” part can be left alone. That’s for translation purposes if you ever need it.

 

Next is the description of the widget:

 

You can make this what you want. It will show up in your widget area.

Here’s what all that looks like in my widget area.
new-widget-area

 

Call in Your Widget with Code

Next you’ll need to put some code into your theme’s template files where you want the new widget area to show up on your site.

You’ll need to change the line of code below to make sure it matches the ID that you have in your code above. In my example, it’s my-new-widget.

I have decided I wanted my new widget area to show up at the bottom of all my posts. So I put my line of code above in my content.php file just before the end of the regular content area.

(Note: your theme’s code my look different from this, and you may need to place your code in a different file.)

widget-code

Adding Your Widgets to Your New Area

Next, simply add whatever widgets you want into your new area.

In my case, I’ve put a Recent Posts widget and a Search widget into my new widget area.

 

widgets-in-widget-area

 

And here’s what that looks like in action.

 

in-action