简体   繁体   English

通过Functions.php删除Wordpress RSS内容

[英]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. 我创建了一个Wordpress简码,该简码可以接受[quote] ... [/ quote]之间的任何文本,并使其成为可发推的引号。 It is styled by adding a class of "myQuote" to a div surrounding the text. 通过在文本周围的div中添加一类“ myQuote”来设置样式。

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. 但是,在RSS feed中,我需要整个div(包括div中的引号文本)不包含在帖子文本中。 Is it possible to create a function that removes an entire div (including the text within that div) for the RSS feeds? 是否可以创建一个功能来删除RSS提要的整个div(包括该div中的文本)?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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