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

I have several post formats and I want to use add_filter selectively, applying the filter to some of the post formats but not all. When I do this in my functions.php file it affect all the post formats. It also affects all my custom post types which I want to avoid.

function test_filter($content) {
    $content = "test" . $content;
    return $content;
share|improve this question
up vote 4 down vote accepted

Use get_post_format():

function test_filter($content) {

    $format = get_post_format();

    if ( ! $format )
        return $content;

    if ( 'audio' === $format )
        // do something with audio

    if ( 'aside' === $format )
        // do something with aside

    return "$content <hr>post format: $format";

Since the_content() requires a global $post object to work, get_post_format() will always work. It will return FALSE if the current post type does not support post formats and a post format slug otherwise.

share|improve this answer
I will try that but I'm a bit confused about how I determine which post formats the filter operates. I also don't understand why you have <hr>post format: in there – byronyasgur Apr 17 '13 at 16:39
The extra HTML is just there to show some useful output. I made an update with better examples. – toscho Apr 17 '13 at 16:40
Thanks. That makes sense. – byronyasgur Apr 17 '13 at 16:43

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.