Adding target="_blank" to all comment links?

  • parkerwest

    #6501

    Hello,

    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!

    Prasanna SP

    #34535
    function comment_author_link_new_window() {
    global $comment;

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

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

    $authorlink = $author;
    else
    $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');

    parkerwest

    #34536

    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.