禁止WordPress某个分类不在RSS中显示被订阅

2020年5月1日01:13:20 发表评论 15 人围观

今天在群里有一个网友问到个问题,自己的网站应该是被人订阅过,如果他有较高质量的文章更新,会将他的RSS订阅内容在他一个订阅的网站显示出来,虽然影响不大,但是感觉不好。实际上我们这类情况也是遇到的,比如我们有些网站专门盯着有订阅的内容,然后去阅读,我们可能希望自己的内容不被他人订阅看到。

那有没有方法可以将WordPress RSS订阅内容不被订阅显示呢?

<code class=" language-none">    <span class="com">//排除分类ID</span>
    <span class="kwd">function</span><span class="pln"> no_rss_category</span><span class="pun">(</span><span class="pln">$query</span><span class="pun">)</span> <span class="pun">{</span>
        <span class="kwd">if</span> <span class="pun">(</span><span class="pln"> $query</span><span class="pun">-></span><span class="pln">is_feed </span><span class="pun">)</span> <span class="pun">{</span><span class="pln">
            $query</span><span class="pun">-></span><span class="kwd">set</span><span class="pun">(</span><span class="str">'cat'</span><span class="pun">,</span> <span class="str">'-1, -2'</span><span class="pun">);</span>
        <span class="pun">}</span>
    <span class="kwd">return</span><span class="pln"> $query</span><span class="pun">;</span>
    <span class="pun">}</span><span class="pln">
    add_filter</span><span class="pun">(</span><span class="str">'pre_get_posts'</span><span class="pun">,</span> <span class="str">'no_rss_category'</span><span class="pun">);</span></code>

将代码放到主题Functions.php文件中,可以设定上面的分类ID,就不会被显示在RSS中被人订阅看到。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: