[wp-hackers] Plugin custom page

Mike Little wordpress at zed1.com
Tue Nov 20 17:45:17 UTC 2012

On 20 November 2012 17:18, Chris Taylor - stillbreathing.co.uk <
chris at stillbreathing.co.uk> wrote:

> Hi,
> Thanks for the replay but this is (ignoring abstractions) exactly what
> I'm doing. I've got a URL like this:
> mysite.com/?voucher=abc123
> Which then uses template_redirect to check if a voucher is being
> requested, then uses add_filter( 'the_content', ...) to change the
> content that is being output to display my form. The problem is that
> when the site homepage is displaying multiple blog entries (as a
> standard installation does) then the add_filter( 'the_content', ...)
> call gets run *once per post* leading to multiple instances of my
> modified content down the page.
> I need a way to say "when this querystring parameter is set display
> this content once and once only, within the page/single/index
> template".
Quick solution: Remove your filter in the filter code itself.

add_filter( 'the_content', 'my_content_filter');
function my_content_filter($content) {
 if ( some_test() ) { // check my special conditions
     $content .= add_my_extra_content();
     remove_filter( 'the_content', 'my_content_filter');
return $content;

Mike Little

More information about the wp-hackers mailing list