简体   繁体   中英

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?

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');

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM