Remove WordPress RSS Content Via Functions.php

I’ve created a WordPress shortcode that takes any text between [quote]…[/quote] and makes it a tweetable quote. It is styled by adding a class of “myQuote” to a div surrounding the text.

However, in the RSS feeds, I need the entire div (including the quote text inside the div) to not be included with the post text. Is it possible to create a function that removes an entire div (including the text within that div) for the RSS feeds?

Read More

Here is the function that creates the shortcode:

function the_quote( $atts, $content = null ) {
    extract(shortcode_atts(array(), $atts));
$out = '<div class="myQuote"><a href="http://twitter.com/home?status='.do_shortcode($content). '%20'.'http://cmsucks.us/?p=' . get_the_ID(). '" ></a>'.do_shortcode($content). '</div>';
    return $out;
}
add_shortcode('quote', 'the_quote');

I’ve tried this but it doesn’t work (it makes my entire site invisible):

function my_function($content) {

if(is_feed()) {  

    $div = '<div class="myQuote">';
    $closeDiv = '</div>';
    // Make sure the offending div is there.
    if (strpos($content, $div) !== false) {
         // Remove div.
         $content = str_replace($div, '', $content);
         // Remove one ending div tag.
         $content = str_replace('$closeDiv', '', $content, 1);
    }
    return $content

}

}
add_filter('the_content', 'my_function');

Related posts

Leave a Reply

1 comment

  1. Not sure about your desired final result, but I think it’s a matter of:

    add_shortcode('quote', 'the_quote');
    
    function the_quote( $atts, $content = null ) {
        extract(shortcode_atts(array(), $atts));
    
        if( is_feed() )
            $out = 'Something else';
        else
            $out = '<div class="myQuote">[...]</div>';
    
        return $out;
    }