评论链接重写

转自大前端,优化内部链接不能让利益跑了。

<span style="color:#a50">//评论链接重写</span><br><span style="color:#708">function</span> <span style="color:#000">add_redirect_comment_link</span>(<span style="color:#00f">$text</span> = <span style="color:#a11">''</span>){<br>    <span style="color:#000-2">$text</span>=<span style="color:#000">str_replace</span>(<span style="color:#a11">'href="'</span>, <span style="color:#a11">'href="'</span>.<span style="color:#000">get_option</span>(<span style="color:#a11">'home'</span>).<span style="color:#a11">'/?r='</span>, <span style="color:#000-2">$text</span>);<br>    <span style="color:#000-2">$text</span>=<span style="color:#000">str_replace</span>(<span style="color:#a11">"href='"</span>, <span style="color:#a11">"href='"</span>.<span style="color:#000">get_option</span>(<span style="color:#a11">'home'</span>).<span style="color:#a11">"/?r="</span>, <span style="color:#000-2">$text</span>);<br>    <span style="color:#708">return</span> <span style="color:#000-2">$text</span>;<br>}<br><span style="color:#708">function</span> <span style="color:#000">redirect_comment_link</span>(){<br>    <span style="color:#000">$redirect</span> = <span style="color:#000">$_GET</span>[<span style="color:#a11">'r'</span>];<br>    <span style="color:#708">if</span>(<span style="color:#000">$redirect</span>){<br>        <span style="color:#708">if</span>(<span style="color:#000">strpos</span>(<span style="color:#000">$_SERVER</span>[<span style="color:#a11">'HTTP_REFERER'</span>],<span style="color:#000">get_option</span>(<span style="color:#a11">'home'</span>)) !== <span style="color:#219">false</span>){<br>            <span style="color:#000">header</span>(<span style="color:#a11">"Location: $redirect"</span>);<br>            <span style="color:#000">exit</span>;<br>        }<br>        <span style="color:#708">else</span> {<br>            <span style="color:#000">header</span>(<span style="color:#a11">"Location: "</span>.<span style="color:#000">bloginfo</span>(<span style="color:#a11">'url'</span>).<span style="color:#a11">"/"</span>);<br>            <span style="color:#000">exit</span>;<br>        }<br>    }<br>}<br><span style="color:#000">add_action</span>(<span style="color:#a11">'init'</span>, <span style="color:#a11">'redirect_comment_link'</span>);<br><span style="color:#000">add_filter</span>(<span style="color:#a11">'get_comment_author_link'</span>, <span style="color:#a11">'add_redirect_comment_link'</span>, <span style="color:#164">5</span>);<br><span style="color:#000">add_filter</span>(<span style="color:#a11">'comment_text'</span>, <span style="color:#a11">'add_redirect_comment_link'</span>, <span style="color:#164">99</span>);
评论 (3)
  1. 沙发
    Tuccuay 2012-11-08 02:14

    这是把评论者的链接都转回自己的首页么。。。

    • 回复
      老蔡 2012-11-29 03:14
      @Tuccuay 看似是给评论链接加/?r=url转向的wordpress的代码,不过有链接的评论会自动等待审核的,没事吧。
    • 回复
      常阳小站 2012-12-28 05:48
      @Tuccuay :mrgreen: 就加个跳转吧,我也加了,有明显作用吗?