[英]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.