我有一个适合我的系统,我可以在帖子中添加一个附属标签,然后在我的函数中添加此代码。php文件在帖子开头添加了一条免责声明:
/* Add disclaimer to top of POSTS that contain affiliate tag */
function tt_filter_the_content( $content ) {
if (has_tag(\'affiliate\'))
$custom_content = \'<hr><p><em>Disclosure: This post contains affiliate links and we may receive a referral fee (at no extra cost to you) if you sign up or purchase products or services mentioned.</em></p><hr>\';
$custom_content .= $content;
return $custom_content;
}
add_filter( \'the_content\', \'tt_filter_the_content\' );
我用这个方法已经有一段时间了,效果很好。然而,我注意到,在我的摘要摘录和提要上,它也显示了免责声明。这使得它有点凌乱,并切断了显示的大量摘要文本。
有没有办法过滤掉应用于摘要和我的RSS提要的内容?
最合适的回答,由SO网友:gdaniel 整理而成
您可以这样做:
/* Add disclaimer to top of POSTS that contain affiliate tag */
function tt_filter_the_content( $content ) {
if (has_tag(\'affiliate\') && is_single())
$custom_content = \'<hr><p><em>Disclosure: This post contains affiliate links and we may receive a referral fee (at no extra cost to you) if you sign up or purchase products or services mentioned.</em></p><hr>\';
$custom_content .= $content;
return $custom_content;
}
add_filter( \'the_content\', \'tt_filter_the_content\' );
现在,您正在检查标记是否存在,以及它是否是一篇文章。如果此消息仍显示在提要中,则可以将If语句更改为如下内容:
if ((has_tag(\'affiliate\') && is_single()) && !is_feed())