Article directory
How can I open and redirect to a new window for WordPress commenter links?
Comment external links automatically transfer to internal link codes
If you don’t want some people to intentionally fill in the URL of the blocked website in the commenter’s link, because such a link has the risk of being blocked.
Therefore, this article continues to share: WordPress commenter external link automatic conversion to internal link code.
Step 1: Automatically convert the external link of the article into the internal link code
Please complete the code in this tutorial, " How to convert backlinks to internal links in WordPress? Code to automatically convert article backlinks to internal links, " before continuing with this tutorial.
Step 2: Add Commenter Link Jump Code
Add the following code to the function.php file of your WordPress theme.
2-to-1 code:
- 1) [Recommended] The commenter link jumps and opens the code in a new window (base64 encryption)
- 2) The commenter link jumps and opens the code in a new window (no encryption)
1) [Recommended] The commenter's link jumps and the new window opens the code (base64 encryption):
// 评论者链接跳转并新窗口打开(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) The commenter link jumps and opens the code in a new window (no encryption):
// 评论者链接跳转并新窗口打开(无加密)
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>";If you want the reviewer's jump link to be able to display the URL, you can choose no encryption code.
Hopefully, the article "How to open and redirect WordPress commenter links in a new window? Code for automatically converting external comment links to internal links" shared on Chen Weiliang's blog ( https://www.chenweiliang.com/ ) will be helpful to you.
Feel free to share this article's link: https://www.chenweiliang.com/cwl-631.html
