Advertisement
  1. Code
  2. WordPress

Don't Ignore Your WordPress Footer

Scroll to top
Read Time: 9 min

Footers are often an overlooked aspect of designing a site - when they can actually be kinda handy and informative. In this tutorial we'll go through some options you can have for your WordPress site.

Preface

As per usual, with these tutorials, you'll need a WordPress directory. By now, if you've been doing them you should already have one setup! If not, there are tutorials on running Wordpress locally here for Windows, and here for OS X.

We'll be going through how to create a static footer with all the information you need, then we'll make it dynamic so you can edit it all via WordPress Backend!

Download these images, and place them in a new folder in the wp-content/themes. Name the folder 'WPFooter'.

Step 1 - The WordPress code

Quickly, place this code in a new file 'style.css' within the new WPFooter folder:

1
/*  

2
Theme Name: WPFooter

3
Theme URI: https://code.tutsplus.com

4
Description: A handy WordPress footer.

5
Version: 1.0

6
Author: Harley Alexander

7
Author URI: http://www.baffleinc.com/

8
*/

If you open up your WordPress directory in a browser, navigate to wp-admin/themes.php, and select the new theme!

"

We'll only show a short header and a simple loop for this. Later on in the tutorial, we'll go through having multiple Sidebars (one for the sidebar, one for the footer). We'll start off with an easy base:

1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
<html xmlns="http://www.w3.org/1999/xhtml">
3
<head profile="http://gmpg.org/xfn/11">
4
5
	<title><?php bloginfo('name'); ?><?php wp_title(); ?></title>
6
7
	<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
8
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" />
9
	<?php wp_head(); ?>
10
</head>
11
<body>
12
	<h1><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a></h1>
13
	<div id="wrapper">
14
		<div id="content">
15
			<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
16
				<div class="entry">
17
					<h2><?php the_title(); ?></h2>
18
					<?php the_content(); ?>
19
				</div>
20
			<?php endwhile; endif; ?>
21
		</div>
22
		<div id="sidebar">
23
			
24
			<!-- sidebar here -->
25
			
26
		</div>
27
		<div id="footer">
28
			
29
			<!-- footer here -->
30
			
31
		</div>
32
		<div class="clearfix"></div>
33
	</div>
34
</body>
35
</html>

I know that's a lot, but it's all pretty basic stuff, and really besides the point of what the tutorial is about, so it's not a huge deal. Basically some header info for a WordPress blog, a short header (that'll become a nice header picture), and a short loop to display the content.

Next up, we'll stick in a static Sidebar. Replace the 'sidebar here' comment with:

1
<ul>
2
	<li><h3>Subscribe</h3>
3
		<ul>
4
			<li><a href="#">Subscribe via RSS</a></li>
5
			<li><a href="#">Subscribe via Email</a></li>
6
			<li><a href="#">Subscribe via FeedBurner</a></li>
7
		</ul>
8
	</li>
9
	<li id="ads"><h3>Ads</h3>
10
		<ul>
11
			<li>Advertise Here</li>
12
			<li>Advertise Here</li>
13
			<li>Advertise Here</li>
14
			<li>Advertise Here</li>
15
		</ul>
16
	</li>
17
</ul>

This is just, once again your regular sidebar. The ads we'll make pretty later on in CSS code... Now we need the interesting part: the footer.

Like I said above, it's becoming more and more prominent for Websites to have more informative and useful footers, rather than just a dumb Copyright name bar. So instead, we're gonna fill it with content to direct readers to other pages. After all, content is king, right? This is the footer:

1
<div><h3>Archives</h3>
2
	<ul><?php wp_get_archives('type=monthly'); ?></ul>
3
</div>					
4
<div><h3>Recent Posts</h3>
5
    <ul><?php wp_get_archives('type=postbypost&limit=10'); ?></ul>
6
</div>					
7
<div><h3>About</h3>		
8
    <p>Hello, this blog is about a whole lot of junk. In fact, the description is pretty self explanitory: <?php bloginfo('description'); ?>. Enjoy your stay and we hope to see you back!</p>
9
</div>					
10
<div><h3>Links</h3>		
11
    <ul><?php wp_list_bookmarks('title_li=&categorize=0'); ?></ul>
12
</div>					
13
<div class="clearfix"></div>

Finally something interesting!

Already we've got a footer that's interesting. It doesn't look much like a footer right now though, so let's jump into the CSS!

Step 2 - CSS

Let's get some prettiness going. Open style.css, and let's get coding!

1
*{
2
	margin: 0;
3
	padding: 0;
4
	outline: 0;
5
}
6
7
body{
8
	background-color: #e3e3e3;
9
	padding: 30px 0;
10
	font: 12px "Lucida Grande", Lucida, Verdana, sans-serif;
11
}
12
13
.clearfix{
14
	display: block;
15
	clear: both;
16
	width: 1px;
17
}
18
19
#wrapper{
20
	width: 960px;
21
	margin: 0 auto;
22
	background: #fff;
23
	padding: 30px 0;
24
}

We start off with some basic 'reset' info, that aligns everything, makes the text normal, and defines a class that is our 'clearfix'.

Now we'll fix up the header. Remember the images folder you unzipped at the start? There's an image in there called 'mywebsite.png'. I was lazy, and made an image with some effects for this part.

It wont display the name of your blog, but it'll display 'My Website'. This technique shows how image replacement is done via CSS safely...

1
h1{
2
	margin: 40px auto 0;
3
	width: 930px;
4
	position: relative;
5
	top: -30px;
6
}
7
8
h1 a{
9
	color: #b3b7ba;
10
	text-decoration: none;
11
	display: block;
12
	width: 203px;
13
	height: 38px;
14
	text-indent: -999em;
15
	background: url(images/mywebsite.png) no-repeat right top;
16
	float: right;
17
}

As you can see, the 'a' has been expanded and blocked to fit the background image of the 'My Website' image. This is a quick and dirty way to do it - also cross browser I believe!

Moving on, we now style the content section:

1
#content{
2
	padding: 30px;
3
	float: left;
4
	width: 650px;
5
}
6
7
h2{
8
	letter-spacing: -2px;
9
	text-transform: uppercase;
10
	font-size: 16px;
11
	margin-bottom: 10px;
12
}
13
14
.entry{
15
	margin-bottom: 20px;
16
}
17
18
.entry a{
19
	color: #164774;
20
	text-decoration: none;
21
}

Already the layout starts to form, but the Sidebar and Footer still need some work, and de-squashifying!

We can do some of the styling to the Sidebar, but not all of it. Seeing as we're aiming for universal widgets, most of the styling for the Sidebar Widgets can be done along with the Footer's.

1
#sidebar{
2
	float: left;
3
	width: 220px;
4
	margin: 0 10px;
5
	padding-top: 30px;
6
}
7
8
#sidebar>ul>li{
9
	margin-bottom: 10px !IMPORTANT;
10
}
11
12
#ads li{
13
	display: inline-block;
14
	width: 100%;
15
	background: #f7f7f7;
16
	height: 50px;
17
	text-align: center;
18
	margin-bottom: 10px;
19
	color: gray;
20
	line-height: 50px;
21
	border: 1px solid;
22
}

If you refresh, you'll notice it's still a bit squashy. Let's fix that up with some styling for the Footer and Sidebar

1
#footer{

2
	clear: both;
3
}
4
5
#footer div, #sidebar>ul>li{

6
	float: left;
7
	width: 220px;
8
	margin: 0 10px;
9
	background: url(images/modalBox.png) repeat-y center top;
10
	color: #fff;

11
}
12
13
#footer p{

14
	padding: 10px;
15
}
16
17
#footer a, #sidebar a{

18
	color: #fff;

19
	text-decoration: none;
20
}
21
22
#footer h3, #sidebar h3{

23
	margin-bottom: 10px;
24
	background: url(images/modalBoxHeader.png) no-repeat center top;
25
	height: 14px;
26
	font-size: 12px;
27
	text-align: center;
28
	color: #fff;

29
	font-weight: normal;
30
	text-shadow: #000 1px 1px 3px;

31
}
32
33
#footer ul, #sidebar ul>li>ul{

34
	list-style: none;
35
	padding: 10px;
36
	background: url(images/modalBoxFooter.png) no-repeat center bottom;
37
}
38
39
#footer ul li{

40
	padding-bottom: 5px;
41
}

That's a heck of a block! But now your WordPress blog should look a lot more interesting! That also splits the 4 footer sections into 4 columns - for nice, neat UI!

All done! That's the manual part of the site done. Now that that's done though, we're going to take this one step further and make it 100% manageable through WordPress Admin.

Step 3 - Making it Dynamic

Dynamic Sidebars are a fantastic built-in function of WordPress. They're easy to use, and basically provides a way to manage more of your content through a Web Interface. Let's make our index.php sidebar-compatible.

Firstly, we'll replace the huge chunks of code that made up our Sidebar and Footer with dynamic code. Replace everything within the #sidebar div>ul with:

1
<?php if(function_exists('dynamic_sidebar') && dynamic_sidebar(Sidebar)) : ?>
2
<?php endif; ?>

And replace everything between the #footer div with:

1
<?php if(function_exists('dynamic_sidebar') && dynamic_sidebar(Footer)) : ?>
2
<?php endif; ?>

If you refresh your page, everything'll disappear. Create a new file in the directory called functions.php, and let's get coding!

We need to create two functions - both 'register_sidebar()'. Register one for the actual Sidebar, and one for the Footer.

1
<?php
2
	if(function_exists('register_sidebar')){
3
		register_sidebar(array('name' => 'Sidebar',
4
			'before_widget' => '<li>',
5
			'after_widget' => '</li>',
6
			'before_title' => '<h3>',
7
			'after_title' => '</h3>',
8
		));
9
		register_sidebar(array('name' => 'Footer',
10
			'before_widget' => '<div>',
11
			'after_widget' => '</div>',
12
			'before_title' => '<h3>',
13
			'after_title' => '</h3>',
14
		));
15
	} 
16
?>

Those arrays are the series of information to attach to each sidebar. The name (so we can select the different ones in WordPress Admin), and the information to put before/after(container) each widget, and before/after each header. Because our code is specific to h3s, we need to tell it to wrap in h3s. Our footer sections are divs, so we need to wrap them in divs instead of the default lis. Simple! If you refresh, you may or may not find content waiting for you. If not, we'll fix that in the next step.

Step 4 - The Sidebar Contents

As I said, there may or may not be content waiting. This is how you edit it. Go the WP Dashboard, and visit the widgets page via design (For WP 2.3+) (Dashboard>Design>Widgets). In the right hand column, there should be your sidebar!

You can now skip between them, save changes, revisit your page and have the content edited easily via a Web Interface instead of trawling through code! Just make sure your 'Footer' Sidebar only has 4 widgets max, as otherwise it'll start bleeding onto the next line.

Wrap up

So here takes up your last excuse not to have an interesting footer - you now know how to do it easily. It's essentially an extra sidebar. This also saves a whole lot of precious space in your sidebar that you can fill with much more important stuff such as feeds, notices, etc. If you have an interesting footer yourself, let us know about it!

Advertisement
Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.