通过Functions.php删除Wordpress RSS内容

时间:2014-04-04 04:51:19

标签: wordpress

我创建了一个Wordpress短代码,它在[quote] ... [/ quote]之间接受任何文本,并使其成为推文引用。它通过在文本周围的div中添加一个“myQuote”类来设计样式。

但是,在RSS提要中,我需要整个div(包括div中的引用文本)不包含在帖子文本中。是否可以创建一个函数来删除RSS提要的整个div(包括该div中的文本)?

以下是创建短代码的函数:

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

我已经尝试了这个但它不起作用(它使我的整个网站不可见):

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

1 个答案:

答案 0 :(得分:0)

不确定您想要的最终结果,但我认为这是一个问题:

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