How to hook into the footer

How to hook into the footer

I think this comes up in the forum at least once a week, so here's some handy tips & instructions. First though, some explanations of the terminology.

Hook - what a plugin does when we want it to "hook" into, or run with, whatever wordpress is doing.
Action - does what it says, it acts.
Function - in php, a function is a tiny bit of code that does something, especially if it's something we want to do often. We write a function, then we call it.

Simply put, this is a two-step process. We add a function as an action, then we hook into WPMU . Kinda like catching a lift.

Are you ready to write a plugin? Hang on, because here we go:


/* We have to start our php with an opening statement.
If we really want to be fancy we can add some things here in the comments to tell everyone what this does. */

Plugin Name: your snazzy new plugin
Description: Adds whatever we want to the footer
Author: your name
Version: 1.0
Author URI: where your plugin can be found, or your website

function your_function_name () { ?>

/* see what we did there? We declared a function then closed our php again. Why? So we can add whatever html goodies we like. */

<p><em>This blog is provided by <a href="<?php get_settings('siteurl'); ?>"><?php get_settings('sitename'); ?></a>.</em></p>

/* Now every blog on our system will get this sentence inserted into the footer of whatever theme they used. And we did not have to edit every single theme. I know you picked something like 250 right? */

<?php }

/* We opened up our php again. we have to tell WPMU something important. */
add_action('wp_footer', your_function_name');

/* Ta da! This is the magic line folks. Let's close up shop now. */

Make sure there's nothing behind that last >, no whitespace, no line break. .Now, before you go too far, there's one HUGE CAVEAT for this working. Every theme must haveย  <?php wp_footer(); ?> somewhere in the footer.php file. Preferably right where you want the contents of your new shiny plugin to show up. Most themes have it, so if you try this and it doesn't show, check the theme's footer file first.

I bet you're already thinking of other things you could put here, like your Google analytics code. ๐Ÿ˜‰

  • Dr. Mike Wendell
    Posted at 21:24h, 05 July Reply

    I can never remember if it’s wp_head or wp_header or wp_foot or wp_footer. I have to work that out some day. ๐Ÿ™‚

  • IndieLab
    Posted at 21:54h, 05 July Reply

    Great post, very helpful! The possibilities are truly endless for what can be hooked into the footer.

    I have one question about your post though…what 250 are you referring to in this sentence…”I know you picked something like 250 right?”

  • WPGlamour
    Posted at 23:40h, 05 July Reply

    But you have to check to see where exactly in the theme that function has been used and how will the template look once you add text or anything else to that function.

    @Dr. Mike Wendell,
    Just open footer.php and look for the function name and then use it in the code, you don’t have remember it by hart.

  • Andrea
    Posted at 09:14h, 06 July Reply

    Indielab – 250 means 250 themes. Imagine trying to edit them all manually. ๐Ÿ™‚

    WPGlamour – yep, you’ll have to check and see how it looks too. For some things, like Google Analytics code, you can skip that part as it won’t be rendered on the page.

  • Terni
    Posted at 15:51h, 06 July Reply

    Quick and neat as always. I would add a couple of lines.. like how/where to add the call to the footer function in themes that are not provided with and the same tutorial for the header.
    I mean the footer is ok but sometimes you would like to add it to the start of the page… like a navigation menu or google ads, and so on.
    I don’t know if there is such a thing in wordpress mu/wordpress themes but it would be nice to find a way to insert .js as well in the section.
    Let’s assume you want some nice js fx in this repeating section, you should be able to add js libraries in the head section.
    For example, a nice thing to add to all the blog network is something similar to what you can see here where on mouse over the “network menu” comes down (scriptaculous is used here but u can use mootools or something else)

  • Bookmarks about Php
    Posted at 10:51h, 10 August Reply

    […] – bookmarked by 4 members originally found by igaum on 2008-07-31 How to hook into the footer – bookmarked by 4 members originally […]

  • sandg
    Posted at 08:17h, 20 August Reply

    This is great provided I want to track hits throughout the whole WPMU, rite? Any way to make google analytics work for individual blog? Tq

  • » Blog Archive » links for 2009-01-17
    Posted at 11:51h, 07 February Reply

    […] WPMU Tutorials ยป How to hook into the footer […]

  • Webmaster Code Promo
    Posted at 04:28h, 19 March Reply


    Great intro, straight to the point. Thanks, I tink I now understand the “HOOK” feature.

    Now, a very basic question: where do I find the full list of HOOKs??? I’ve digged into wordpress/wordpressmu and google, without success. Is there such a list at all?

    Otherwise, how do you proceed to find the hook name (and feature attached to it) ?


  • kunal
    Posted at 08:04h, 03 June Reply

    Is it possible to hook into the footer of only certain blogs? i.e. if I want to hook into the footer of only my main blog or only the blogs that the site admin has created, is there a way I can do that?

  • Ron
    Posted at 15:21h, 03 June Reply

    Sort of. You would have to hook the footer on all blogs and test to see if the blog belonged to admin.
    [rq=100,0,blog][/rq]Geek of the week

  • Sam H
    Posted at 12:43h, 11 June Reply

    apologies if this seems a particularly stoopid question, but where do you place the script?!

  • Sam H
    Posted at 12:46h, 11 June Reply

    [edit] fixed! sorry! ignore that last comment

    Thank you very much for this solution by the way!

  • lisa
    Posted at 22:52h, 18 August Reply

    For the really slow n00b, you omit an important usage instruction.

    Are we creating an actual plugin to be placed in the plugins folder?


    Is this inserted into the existing footer.php file? (I’m guessing yes)

    It is an informative little tutorial though ๐Ÿ™‚

  • Ron
    Posted at 00:02h, 20 August Reply

    Yes, you would be creating a plugin and putting it in either the plugins or mu-plugins folder. In the mu-plugins folder, it would be applied across the site.

  • Pippa
    Posted at 09:45h, 25 November Reply

    Oh brilliant! Thanks for such a clear explanation – I was able to get Google Analytics into my work’s blogs with no worries! I’m now thinking of many other ways to use this!

  • Minotauro
    Posted at 04:55h, 12 January Reply

    This is what I see on the footer of all my blogs when I follow your instructions:

    Why is that happening?

    Thank you

  • Dave
    Posted at 21:46h, 05 July Reply

    What a simple solution to a plaguing problem. Thanks!

    The way you have the plugin constructed, the PHP comments fall outside the PHP code, making them appear in HTML. Then again, because they are purely instructional, people would remove them (I think).

    • Ron
      Posted at 00:14h, 07 July Reply

      “people would remove them”

      Maybe not initially, but one would hope that seeing the extra strings in the footer would prompt that.

  • Angelverde
    Posted at 17:37h, 19 December Reply

    Gracias ๐Ÿ™‚

Post A Comment