Adding target="_blank" to all comment links?

  • Anonymous



    I was wondering if anyone knows of a code snippet that I can add to my child theme’s functions.php file to add target=”_blank” to all comment author links. Such as when the author adds a URL to link his/her name and when they include links in the actual comment itself. I’m not well versed enough in PHP to be able to create my own. Anyone have any suggestions?

    Thanks in advance!


    function comment_author_link_new_window() {
    global $comment;

    $url = get_comment_author_url();
    $author = get_comment_author();

    if (empty( $url ) || 'http://' == $url)

    $authorlink = $author;
    $authorlink = "<a href='$url' target='_blank' rel='external nofollow' class='url'>$author</a>";

    return $authorlink;

    add_filter('get_comment_author_link', 'comment_author_link_new_window');



    That did the trick. Thanks Prasanna!

Viewing 3 posts - 1 through 3 (of 3 total)

  • You must be logged in to reply to this topic.