How do I make the Commentor's Name Link Open in New Window (12 posts)

  1. bizcoach123
    Posted 7 years ago #

    I've searched the forums and don't see this question/answer. When people leave a comment and also put in their web address, their name becomes a live link to their website. I would like for this link to open in a new window.

    How do I make that happen?

  2. t31os
    Posted 7 years ago #

    The easy way would be to add...


    To the <a> that links the name...

    <a href="http://google.com" target="_blank">Example</a>

  3. bizcoach123
    Posted 7 years ago #

    Sorry, I should have been more clear. This is not a link they are creating themselves or that I am creating.

    "Subscribers" (wordpress role) have a WordPress profile and those who have websites can enter their website address into a form in their profile.

    WordPress automatically takes their website address and uses it to create a live link out of their name when that person makes a comment on my blog posts.

    At this point, those links do not open in a new window.

    My question is where do I go in the code to make a change so that whenever someone leaves a comment, that live link that gets created by WordPress is opening in a new window.

    Thanks for anything you can share!

  4. nocabt
    Posted 7 years ago #

    The comment author link is a WordPress Template tag:


    However, it has no parameters so I don't think you could add a target="_blank" to it. Maybe using some custom PHP?

  5. t31os
    Posted 7 years ago #

    Make your own using...

    <?php get_comment_author(); ?>
    <?php comment_author_url_link(); ?>

    Like this...

    <a href="<?php comment_author_url_link(); ?>" target="_blank"><?php print get_comment_author(); ?></a>

    Currently you should have...
    <?php comment_author_link(); ?>

    My example replaces that...

    It will be in comments.php , or functions.php... depending on the theme.....

    Fortunately i've just been fiddling in that area of a theme so i happened to recall. :)

  6. nocabt
    Posted 7 years ago #

    Ah, very helpful. I only saw comment_author_link which generates a link. comment_author_url of course doesn't.

  7. t31os
    Posted 7 years ago #

    There's a bunch of related links on the page you last linked to.. ;)

  8. SaranR
    Posted 7 years ago #

  9. SaranR
    Posted 7 years ago #

    here is the code your required one:

    <a href="<?php comment_author_url(); ?>" target="about_blank"><?php comment_author(); ?></a>

    Hope you it will work for you


  10. t31os
    Posted 7 years ago #

    There's also a working solution in my previous post (6 posts up from this one)..

  11. rickydeez
    Posted 6 years ago #

    Heres some code to check to see if the Author URL is empty or not.

    $comment_author = get_comment_author_url();
            if (!empty($comment_author)) { ?><a href="<?php comment_author_url(); ?>" rel="nofollow" target="_blank"><?php comment_author(); ?></a><?
            } else {
  12. Wes
    Posted 6 years ago #

    What about the people in this forum who's name are an active link? How do I make my name an active link in this forum?

    Ex. t31os is an active link whereas rickydeez is not.

Topic Closed

This topic has been closed to new replies.

About this Topic