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,可以選擇無加密代碼。
希望陳溈亮博客( https://www.chenweiliang.com/ ) 分享的《WordPress評論者鏈接如何在新窗口打開跳轉?評論外鏈自動轉內鏈代碼》,對您有幫助。
歡迎分享本文鏈接:https://www.chenweiliang.com/cwl-631.html