Some questions regarding filter

It depends whether you’re trying to hook to an existing filter or hook to one you’ve made, looking at your second code sample suggests you’re asking about making your own filter.

And, yes you can add your own, something like this is valid inside your loop.

<?php echo apply_filters( 'my_blah_filter', '<p>Blah blah some text goes here</p>' ); ?>

You can then hook that filter, as you would with regular WordPress filters, eg.

add_filter( 'my_blah_filter', 'my_filter_for_blah' );
function my_filter_for_blah( $filter_content ) {
    // Uncomment the next line to see the effect of not replacing it
    $filter_content="new content";
    return $filter_content;
}
add_filter( 'my_blah_filter', 'wpautop' );

Let me know if that helps. 🙂

Leave a Comment