WordPress評論者鏈接如何在新窗口打開跳轉?評論外鏈自動轉內鏈代碼

WordPress評論者鏈接如何在新窗口打開跳轉?

評論外鏈自動轉內鏈代碼

如果不希望某些人有意在評論者鏈接裡,填寫被牆的網站網址,因為這樣的鏈接,有被牆的風險。

所以,本文繼續分享:WordPress評論者外鏈自動轉成內鏈代碼

第1步:完成文章外鏈自動轉成內鏈代碼

請先完成這篇教程《WordPress如何將外鏈轉內鏈?文章外鏈自動轉成內鏈代碼》裡的代碼之後,才繼續操作本文教程。

第2步:添加評論者鏈接跳轉代碼

將以下代碼,添加到WordPress主題的 function.php 文件裡。

2 選1 代碼:

  • 1)【推薦使用】評論者鏈接跳轉並新窗口打開代碼(base64加密)
  • 2)評論者鏈接跳轉並新窗口打開代碼(無加密)

1)【推薦使用】評論者鏈接跳轉並新窗口打開代碼(base64加密):

// 评论者链接跳转并新窗口打开(base64加密)
 function commentauthor($comment_ID = 0) {
 $url = get_comment_author_url( $comment_ID );
 $author = get_comment_author( $comment_ID );
 if ( empty( $url ) || 'http://' == $url )
 echo $author;
 else
 echo "<a href='go.html?url=".base64_encode($url)."' rel='external nofollow' target='_blank' class='url'>$author</a>";
 }

2)評論者鏈接跳轉並新窗口打開代碼(無加密):

// 评论者链接跳转并新窗口打开(无加密)
 function commentauthor($comment_ID = 0) {
 $url = get_comment_author_url( $comment_ID );
 $author = get_comment_author( $comment_ID );
 if ( empty( $url ) || 'http://' == $url )
 echo $author;
 else
 echo "<a href='go.html?url=$url' rel='external nofollow' target='_blank' class='url'>$author</a>";

如果你希望評論者的跳轉鏈接,能夠顯示URL,可以選擇無加密代碼。

發表評論

您的郵箱地址不會被公開。 必填項已用 * 標註

回到頁首