簡體   English   中英

通過Functions.php刪除Wordpress RSS內容

[英]Remove Wordpress RSS Content Via Functions.php

我創建了一個Wordpress簡碼,該簡碼可以接受[quote] ... [/ quote]之間的任何文本,並使其成為可發推的引號。 通過在文本周圍的div中添加一類“ myQuote”來設置樣式。

但是,在RSS feed中,我需要整個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');

不確定您想要的最終結果,但是我認為這是一個問題:

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