0

I wanted to add target=_blank to comment author link and also wanted to add redirection link to url.

So here is what I did:

<a href="site.com/go?url=<?php echo get_comment_author_url(); ?>" target="_blank"><?php echo get_comment_author(); ?></a>

It works, but if comment author has no website I want to echo this:

<span><?php echo get_comment_author(); ?></span>

So, how to check if comment author entered url field?

Tried this but did not work:

    <?php if ( ! empty( $fields['url'] ) )  { ?>

Solution

Thanks to shanebp answer here

<?php if( get_comment_author() == get_comment_author_link() ) 
                    comment_author_link();
                    else 
                     echo '<a href="site.com/go?url='. get_comment_author_url() .'" target="_blank">'. get_comment_author() .'</a>' ?>
  • 1
    You already have the access to get_comment_author_url() which returns either URL or empty string. What is the problem? – Max Yudin Sep 15 '18 at 12:47
  • I want to add site.com/go?url= to author url. So when author url empty this still show up: site.com/go?url= – ahmet Sep 15 '18 at 12:48
  • And what is the problem to check what does get_comment_author_url() return? Please interpret your question differently as it's completely unclear. what you are asking for. – Max Yudin Sep 15 '18 at 13:07
  • I found solution if( get_comment_author() == get_comment_author_link() ) does the job. The problem was I add something to url, if url returns empty, still show up what I added. – ahmet Sep 15 '18 at 13:11
  • 1
    If you have figured out the answer, then add your solution as an answer then mark it as correct. Answering your own question is encouraged. – yobddigi Sep 15 '18 at 14:29
0

Solution

Thanks to shanebp answer here

<?php if( get_comment_author() == get_comment_author_link() ) 
                    comment_author_link();
                    else 
                     echo '<a href="site.com/go?url='. get_comment_author_url() .'" target="_blank">'. get_comment_author() .'</a>' ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.