How to Add Widgets to WordPress Theme’s Footer

I wanted to use widgets in the footer of my WordPress theme but my wordpress theme didn’t come with a footer-sidebar by default. I didn’t really wanted to change the theme just because of that. So I hacked the wordpress theme to introduce footer-sidebars. If you are looking for a tutorial that explains how you can add sidebars/widgets to the footer of your WordPress theme then keep reading.

wordpress_theme_icon_128

There are really three main parts to introducing a footer sidebar/widget area in your theme:

  1. Registering the Sidebar(s) in the WordPress Theme
  2. Inserting the Sidebars In the WordPress Theme
  3. Putting some style into the sidebars
WordPress has introduced a few new functions recently which makes it hard to write one tutorial that will cater for every theme out there. I have broken this tutorial into smaller sections to cater for the various different themes.

Keep a backup copy of your “functions.php” and “footer.php” file just in case you make a mistake when making the code changes.

Adding Footer Widget to a Modern Theme

Do the following if your theme is relatively new.

1. Register the footer widget area

Open the functions.php file from the WordPress Theme Editor and search for the following line of code:

register_sidebar

That should take you to the area where all the sidebars are registered in your theme.

Add the following block of code just below the other sidebar registration code (we are telling it to register 3 footer widget areas):

register_sidebar( array(
'name' => 'Footer Sidebar 1',
'id' => 'footer-sidebar-1',
'description' => 'Appears in the footer area',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => 'Footer Sidebar 2',
'id' => 'footer-sidebar-2',
'description' => 'Appears in the footer area',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => 'Footer Sidebar 3',
'id' => 'footer-sidebar-3',
'description' => 'Appears in the footer area',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );

The following screenshot is taken from the Twenty Twelve theme’s functions.php file which should give you some perspective as to where you need to insert the above code block.

footer widget area registration example

2. Show the footer widget area in your theme

Open your footer.php file and insert the following block of code where you want to show the footer widgets (this will show the 3 footer widget areas if they have any widgets in them):

<div id="footer-sidebar" class="secondary">
<div id="footer-sidebar1">
<?php
if(is_active_sidebar('footer-sidebar-1')){
dynamic_sidebar('footer-sidebar-1');
}
?>
</div>
<div id="footer-sidebar2">
<?php
if(is_active_sidebar('footer-sidebar-2')){
dynamic_sidebar('footer-sidebar-2');
}
?>
</div>
<div id="footer-sidebar3">
<?php
if(is_active_sidebar('footer-sidebar-3')){
dynamic_sidebar('footer-sidebar-3');
}
?>
</div>
</div>

3. Style the footer widget area to your liking

Add the following block of CSS code to your theme’s style.css file to add some basic styling to the footer widgets you just added. Customize it a little to match your needs. Our how to use firebug tutorial should come in handy for this.


#footer-sidebar {
display:block;
height: 250px;
}

#footer-sidebar1 {
float: left;
width: 340px;
margin-left:5px;
margin-right:5px;
}

#footer-sidebar2 {
float: left;
width: 340px;
margin-right:5px;
}

#footer-sidebar3 {
float: left;
width: 340px;
}

Adding Footer Widget to an Older Theme

Do the following if the theme you are using is a bit old:

1. Register the Sidebars in the WordPress Theme

Go to the WordPress theme editor and open the Theme Functions (functions.php) file. Now Search for the following line in your Theme Functions (functions.php)

if ( function_exists('register_sidebar') )

Once you find the above line then take a look at the the next line which should look similar to one of the followings depending on how many sidebars you have:

register_sidebar(array(
or
register_sidebars(2,array(

Say for example you have one sidebar in your theme and you want to add three rows of sidebars in the footer area so you can put widgets then overwrite the code with the following:

register_sidebars(4,array(

The above will register 4 sidebars (one that you already have and three more that you are about to introduce in the footer area of your wordpress theme).

2. Insert the Sidebars In the WordPress Theme

Now lets insert the siderbars where we want them in the WordPress theme. In our case we are going to insert in in the footer area of the theme so open the Footer (footer.php) file and insert the following code just above the ‘footer’ division:

<div id="footer-sidebar" class="secondary">
<div id="footer-sidebar1">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(2) ) : ?>
<?php endif; ?>
</div>

<div id="footer-sidebar2">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(3) ) : ?>
<?php endif; ?>
</div>

<div id="footer-sidebar3">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(4) ) : ?>
<?php endif; ?>
</div>

</div>
<div style="clear-both"></div>

3. Put some style into the sidebars

Finally, lets put a little style to all the ‘footer-sidebar’ divisions that we just introduced. Open the Stylesheet (style.css) file and insert the following CSS (you will probably have to adjust the CSS to your need depending on what wordpress theme you are using).

#footer-sidebar {
display:block;
height: 250px;
}

#footer-sidebar1 {
float: left;
width: 340px;
margin-left:5px;
margin-right:5px;
}

#footer-sidebar2 {
float: left;
width: 340px;
margin-right:5px;
}

#footer-sidebar3 {
float: left;
width: 340px;
}

Hope this helps! Now you don’t have to change your beloved WordPress theme just to get footer sidebar/widget :)

Found this article interesting? Subscribe to Tips and Tricks HQ

email icon rss feed icon twitter icon google plus icon

Comments (146 responses)

  1. Polina says:

    Thank you, Your code worked like a charm for me! I just had to style the divs!

  2. Henry says:

    Thanks for the tutorial. The Codex is a heap load of info. Reading this makes it simple.

  3. Rob says:

    I know I sound like another broken record, but just wanted to say that this really helped me out. Thanks for taking the time to put this together!

  4. Jhony says:

    Thank you. I have stuffed around with the footer for hours. GREAT TUTORIAL

  5. chel says:

    OMG THANK YOU!!!!

    I am still in the process of styling this as I type but I can already tell this is TOTALLY going to work!

    You saved me a couple hundred dollars in designer/coding fees. I LOVE you! XOXQ! -chel

  6. Joe Njengah says:

    Awesome …..I had a serious headache getting to fix that 4 footer widgets and your tutorial was the best. Thanks so much for your help

  7. admin says:

    @MEmilsson, Background of the footer widget or the whole theme?

  8. MEmilsson says:

    Hi! Thanks very much for this.

    I got one question thou: How du I change background color to black (for example)?

    BR Mattias

  9. admin says:

    Use the “float” CSS property on the footer widget class and they should go side by side.

  10. MarketLincs says:

    one more query,
    what would be code to keep those 3 footers side by side.Can any one help ..Thank you

  11. MarketLincs says:

    This is really awesome.you are genius .I just added the code and it worked perfect.So we can add as many footer widget areas as we want .cheers

  12. Leo Saballos says:

    Great Tutorial!! You Rock my friend! Like always I had to change some CSS Styles but is working! Thanks Bro.

  13. mohan perera says:

    Clean & Perfect tutorial. I added 3 column footer widgets to my site. Thanks

  14. Tony says:

    AWESOME. Works perfectly!

  15. Dave Allred says:

    Excellent tutorial! Worked right away and after adding a border, background color, box shadow and some text shadows, was exactly what I needed.

    You da man!

  16. admin says:

    @Raymond, you can create a “functions.php” file in your child theme if it doesn’t have one already. Then you should be good to go. WordPress will include the code from both your parent and child theme’s functions.php file and execute it.

  17. Raymond says:

    How would you recommend doing this if you are using a child theme?

  18. Tom says:

    Really great post. Currently i am customizing one theme named kelta wordpress theme and i was facing some difficulties in adding widget. Now this post will help me in customizing the widget. Thanks for sharing.

  19. DirtyDazz says:

    easy tut to follow and worked a charm.. I’m thinking of placing some other widget slots in other areas using the same principle.

    Cheers, DirtyDazz,

  20. cowabango says:

    Great tutorial, simple and to the point. Best of all, IT WORKS! Lol.

  21. Steve says:

    This is an awesome tutorial. I was looking for a straightforward tutorial on how to add widgets to a website footer in WP and this was one of the best ones I found.

  22. mkfolio says:

    Its awesome.. this is what I’m looking for.. thanks.

  23. beedo says:

    Thank you. You made my day. People need to know some back ground have some background with coding before dealing with that ;).

  24. Ashish Negi says:

    Just used your tutorial to embed widgets in the footer for my theme. I was about to change my theme for additional widget areas. Thanks for the hack. Really easy and reliable. Works like magic

  25. Steve Peck says:

    This tutorial is pretty close to perfect. I know it did what I needed it to.. Only thing different was the fact that I had to find the if statement in a different location, but once i di this worked flawlessly.

    Thanks!

  26. Boky says:

    Great arcticle and very helpfull! Thx!!

  27. Rohit says:

    Thank you for your good snippet.

  28. joan says:

    Really works, thanks for the trick!

  29. Tom Watson says:

    Very useful post. I really appreciate your blog.
    Thanks

  30. Raghvendra says:

    Thanks for this tutorial dude…
    I its just a great job..keep it up

  31. Maria says:

    Does anyone know how to add a FOURTH footer area to TwentyEleven? I am using a Twenty Eleven child theme.

    Thanks.

  32. Abir Ganguly says:

    Thanks a lot. its really grt tutorial..

  33. liryc says:

    Wow, thank you very much, this is what I’ve been looking for, I am now editing my template. :D Keep it up!

  34. Jimmy says:

    Thanks for the help. Worked out perfect.,

  35. aero says:

    I love to tackle problems like these and i was going to try and solve this myself but you beat me to it :) and saved me a lot of time. Thanks! I have a nice theme and wanted to display weather forecast widget in the footer and it works perfectly.

  36. JJSWP says:

    Thanks, this worked very well for me. I just had to tweek the code a bit by putting the named dyanamic widget as opposed to number assignments.
    Thank you

  37. Jamil says:

    Good artilce specially for beginners. Now i have learnt the art of adding widgets in footer as well. Will implement it in my next theme.

    Thanks

  38. Really great tips. As i want to learn wordpress so this post might help me…

  39. That was a simple code trick, and yet so many people find it difficult. We used tables for so long to get that effect. Thanks.

  40. Robin says:

    Pretty useful to setup a widget at the footer. Great write up as well. :)

    Robin.

  41. welders says:

    Thank you. I have stuffed around with the footer for hours, now all sorted thanks to your info.

  42. Templates says:

    Awesome, thank you !! i only just started learning wordpress, mostly ive been working with forum software and release free forum skins etc but now i can release free wordpress themes as well.

    Cheers

  43. I’ve been looking for almost 30 minutes regarding how to add footer-sidebar and your post has the easiest and simplest way to do it.

    Thank you so much your such a life saver :D

    -Damien Lewis.

  44. Lusi says:

    Thank you a lot. The tutorial provided is clear enough.
    I try it now.

  45. jewel says:

    I’ve some problem with the footer widget. But finally I’ve solve my problem. Thank you very much.

  46. Chelle says:

    Worked beautifully :) Thank you for the easy step by step copy and paste instructions :)

  47. Kulwant Nagi says:

    This tutorial Really helps me a lot.. thanx a lot because i found this tutorial after too much search…

  48. Vijay says:

    Pretty Simple Huuh. I thought it would be difficult, Thanks for sharing.

  49. aya says:

    Scratch that! I added just above the footer sidebar div, and it cleared up that mess! Thank you so much once again… this tutorial made my theme one that will grow with me and cover my needs for a good deal of time :D

  50. aya says:

    Thank you so much for all your help! I have it working and it has a background, I think it looks MARVELOUS and I am so happy!

    May I ask for one last bit of advice? The footer looks great on all my pages, but it goes a little wonky on my front page : http://www.strawberrykoi.com

    The footer background disappears, the whole thing seems shortened and the top of the footer BG is popping up at the top of my slider. Is this a footer.php issue or…? Any thoughts would be greatly appreciated!!!

Speak Your Mind

*