WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Basically, I've got a plugin that searches for certain tokens in the entire page and replaces the tokens with images. The problem is, I've got one of those tokens in the footer and, as far as I can tell, there's no filter for the footer.

So the question is, is there a way to make a custom filter? And is that the best way to go about doing this? My plugin does a preg_match in the content and, if it finds, for example "{picture here}", it replaces it. I'm not sure how to extend this functionality to the footer, though?

share|improve this question

migrated from stackoverflow.com Jun 21 '11 at 18:31

This question came from our site for professional and enthusiast programmers.

up vote 8 down vote accepted

Most of the footer is straight-up PHP/HTML markup. You apply filters to dynamic content, which is why there isn't a typical footer "filter." That said, it's relatively easy to add your own filters to WordPress.

Let's say your footer.php consists of the following:

</div>    <!-- close main content div>
<div id="footer">
    <p class="copyright">Copyright 2011 By Me</p>

And lets say you want to dynamically replace the word "copyright" with the standard C image using your filter. You'd replace this with:

</div>    <!-- close main content div>
<div id="footer">
    <p class="copyright">
    echo apply_filters( 'my_footer_filter', 'Copyright 2011 By Me' );

This creates a custom filter called "my_footer_filter" and applies it to the text "Copyright 2011 By Me." In your functions.php file, you can use this filter just like you would any other:

function replace_copyright( $copyright ) {
    // do something to $copyright
    return $copyright;
add_filter( 'my_footer_filter', 'replace_copyright' );
share|improve this answer
Thank you! That was exactly what I was looking for. Sadly, that simple answer was extremely hard to find around WP and google at large. – Cyprus106 Jun 21 '11 at 20:34
@EAMann Doesn't this require modifying the theme itself? What if you want this same functionality but don't have any ability to modify themes? (This is a generic plugin and needs to work with any theme) – Nicholas Kreidberg Jan 21 '15 at 20:11
@NicholasKreidberg If the theme doesn't offer a filter, there's nothing you can do. So yes, the above would require editing a theme to add the filter. Actually filtering content, though, could happen in a child theme, plugin, wherever. – EAMann Jan 21 '15 at 22:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.