WordPress: custom the_content filter is removing other filters, ie: wpautop

This is my first time playing with filters, so forgive me if this seems basic. I have done quiet a bit of googling and can’t find anything related to my problem, from everything I have been able to find this should be working without an issue. It’s my understanding that filters added manually run concurrent with any other filters wordpress is automatically running, ie: creating my own filter will run along with wordpress’s default wpautop and wptexturize filters.

But for some reason my added filter is running fine, except now wpautop and wptexturize is failing to run on the_content. After removing my custom filter from functions, the default filters are triggering again. No other plugins installed that are modifying the output. Any help would be super appreciated, along with any general recommendations as to a better way to do this if you see something wrong with my statements.

function tumblr_chat_post($content) {
global $post;
$content = $post->post_content;
if ($post->post_type == 'post') {
    $postcats = wp_get_object_terms($post->ID, 'category');
    foreach ($postcats as $mycat) {
        if ($mycat->name == "chats") {
            $chatoutput = "<dl class="transcript">n";
            $split = preg_split("/(r?n)+|(<brs*/?>s*)+/", $content);
                foreach($split as $haystack) { 
                    if (strpos($haystack, ":")) {
                        $string = explode(":", trim($haystack), 2);
                        //list($who, $what) = explode(":", $haystack, 2);
                        $who = trim($string[0]);
                        $what = trim($string[1]);
                        $row_class = empty($row_class)? " class="alt"" : "";
                        $chatoutput = $chatoutput . "<dt$row_class><b>$who:</b></dt> <dd><i>$what</i></dd>n";
                    }
                    else {
                    // the string didn't contain a needle so we will keep it and output it later
                        $no_chatoutput = $no_chatoutput . $haystack . "n";
                    }
                }
                // print our new formated chat post and push unformatted content to the end of the post.
                $content = $chatoutput . "</dl>n" . $no_chatoutput;
                return $content;
        } 
        else {
        // I don't exist in the defined category, so no processing is needed
        return $content;
        }
    }
} 
else { 
    // I'm not a regular post, so no processing is needed.
    return $content;
}
}
add_filter( "the_content", "tumblr_chat_post", 20);

Related posts

Leave a Reply

1 comment

  1. You’re not passing the already filtered $content into your filter function (and therefore you’re losing any filtering done before you reach your function). It should be defined like so:

    function tumblr_chat_post($content) {
       // rest of your logic m'ere
    }