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:
<?php
/* 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. 
Share This