Most WordPress websites use the same footer throughout their site. What few people know is that it’s actually very easy to show different footers throughout their site using the get_footer function. Using this function you could easily display different sized footers with different content throughout your site.
For example, you could show:
- A large footer area on your home page with featured posts from your website.
- A medium sized footer on your posts (single.php) that displays related posts.
- A small footer on your pages that links to important areas of your site like advertising, archives, sitemap etc.
- A custom footer for your 404 page that shows categories and archive links.
The get_footer Function
The get_footer function only has one parameter; a string that is used to call the correct template.
Most themes use this function with no parameters. When a template such as index.php, page.php or single.php uses get_footer() at the bottom, it inserts the footer.php template. By entering a parameter you can make WordPress call a different template.
For example, if we add this to our single.php template (i.e. the template that is used to display posts):
Then WordPress will insert a template called footer-single.php. Likewise, we could use get_footer(‘page’) to call footer-page.php on pages (page.php), get_footer(‘index’) to called footer-index.php for our home page (index.php) and get_footer(‘404′) to call a template called footer-404.php for our 404 error page (404.php).
It only takes a minute to create your custom template. Most of your time will be spent customising it. Let’s walk through the 3 simple steps required to create a custom footer for your pages. As you know, the WordPress page template is called page.php.
- Copy the code from your existing footer.php template and place it in a file called footer-page.php.
- Upload footer-page.php to your theme folder.
- Open your page.php template via the WordPress theme editor or via a text editor on your computer and look for the call to get_footer() at the bottom of the page. Simply change this to get_footer(‘page’). Save the file (or save and upload if you edited the file on your computer).
Your pages will now insert content from footer-page.php rather than your normal footer.php template. All you need to do is customise your footer-page.php accordingly. It’s up to you how little or how much you change. For example, you could simply use this technique to display a different footer background colour on pages. Perhaps you will keep the same colour scheme and style and simply change the information that is displayed on pages. Alternatively, you could change the layout, colour scheme and content and make it unrecognisable from the original footer.
Displaying Different Footers Using Conditional Tags
Those of you who read my recent article about making WordPress titles SEO friendly will know that it’s very easy to control what content is displayed in different areas of your site using conditional tags.
For example, if your theme doesn’t use category.php and date.php to display category and date archives, you could use the following in index.php to display a different footer on your home page, category archives and date archives:
Note that it’s only useful to use conditional tags for templates that are used for many different areas of your site. Index.php is a prime example of this as it is the fall back template for all templates. If there is no 404.php template, index.php is used, if there is no search.php template, index.php is used. The same goes for taxonomy.php, tag.php, home.php, date.php, archive.php, category.php, single.php, page.php, author.php and attachment.php.
If your theme is missing any of these templates then it will be using index.php instead. If that is the case, you should conditional tags to control what footer is displayed on your site. If your theme does have a dedicated template for a page or area (e.g. author.php for author profiles or category.php for category archives) then you should edit those templates directly instead using get_footer( ‘name’).
I’ve been playing around with over the last day or so. I may still change things around a little however at the moment I have the following setup.
On the home page I show the first two featured posts at the top of the page, therefore on the home page footer I display the 3rd, 4th and 5th featured posts.
On my archive pages I show the the 3 latest featured posts at the top of the page and the 4th, 5th and 6th latest at the bottom of the page.
On blog posts and category archives I show the last 3 featured posts from that category. In the footer the 4th, 5th and 6th featured post from the corresponding category are displayed. I could have used the same template for both categories and posts however I used footer-single.php and footer-category.php just incase I want to customise the footer more later.
On all other pages I display a minimal footer template with some credit links.
It only took me a few minutes to set this up. I can now dictate what featured posts are displayed on my footer in different areas of WP Mods to encourage more visits to premium articles.
The great thing about the WordPress template system is that it makes customising different areas of your website so easy. Very few websites take advantage of the get_footer function though it’s something that is always available, if only to show slightly different content or a different colour scheme on other areas of your site.
If there is any part of this article you are unsure about, please leave a comment or post a thread in the WordPress forums and I’ll do my best to help :)