Title: comment_author_url
Last modified: August 18, 2016

---

# comment_author_url

 *  [andyb2](https://wordpress.org/support/users/andyb2/)
 * (@andyb2)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/comment_author_url/)
 * Hi,
    I am adding this piece of code to my blog
 * 
 * The only problem is that when people do not enter a URL, which i do not require,
   the <?php comment_author_url(); ?> string is empty. The result is that the hyperlink
   becomes the name of the post!
 * Is there a way to omit the blank hyperlink if no URL was specified, but allow
   the hyperlink if a URL was specified?
 * Cheers
    Andy

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [andyb2](https://wordpress.org/support/users/andyb2/)
 * (@andyb2)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/comment_author_url/#post-612917)
 * woops i guess i didn’t escape my characters
    here it is again, kind of!
 * “><?php comment_author(); ?>
 *  Thread Starter [andyb2](https://wordpress.org/support/users/andyb2/)
 * (@andyb2)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/comment_author_url/#post-612918)
 * `<a href="<?php comment_author_url(); ?>"><?php comment_author(); ?></a>`
 *  Thread Starter [andyb2](https://wordpress.org/support/users/andyb2/)
 * (@andyb2)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/comment_author_url/#post-612929)
 * So i tried this piece of javascript
 *     ```
       <script language="JavaScript" type="text/Javascript">
       	if (<?php comment_author_url(); ?> != null) {
        	  document.write('<span class="commentauthor">  <a href="<?php comment_author_url(); ?>"><?php comment_author(); ?></a></span>');
       	} else {
                 document.write('<span class="commentauthor">  <?php comment_author(); ?></span>');
       	}
       </script>
       ```
   
 * but i have now read that document.write is not supported un xhtml.
 * Any ideas what i could do??
    cheers
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/comment_author_url/#post-612931)
 * if that works, and you are just worried about validation, just do this:
 *     ```
       <script type="text/javascript">
       <![CDATA[
       // content of your Javascript goes here
       ]]>
       </script>
       ```
   
 *  Thread Starter [andyb2](https://wordpress.org/support/users/andyb2/)
 * (@andyb2)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/comment_author_url/#post-613049)
 * i am not concerned with validation right now. The script above doesnt work.
 * All i am trying to do is hyperlink a commenters name if they leave a web site
   URL when making a comment. If they dont leave a url i just want to dosplay the
   name with no hyperlink.
 * The reason i am doing this is that i noticed that if you hyperlink all names 
   with the url, then if the filed was left blank then the the default url is the
   name of the post. i dont want that!!
 * so i tried this php code, but it is giving me strange results:-
 *     ```
       <?php
                   $urlentered = comment_author_url();
                  if (!empty($urlentered))
                       echo '<span class="commentauthor"><a href="',comment_author_url(),'" target="_blank">',  comment_author(), ' </a></span>';
                  else
                       echo '<span class="commentauthor">',  comment_author(), ' </span>';
                 ?>
       ```
   
 * The strange result is that the url – when present- gets printed before the span
   tag.
 * I’ve been struggling with this for days now!!!
    cheers
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/comment_author_url/#post-613074)
 * _All i am trying to do is hyperlink a commenters name if they leave a web site
   URL when making a comment. If they dont leave a url i just want to dosplay the
   name with no hyperlink._
 * That’s what WP should do out of the box – without you messing with the code.
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/comment_author_url/#post-613075)
 * the OP has two threads going on this:
 * [http://wordpress.org/support/topic/132824?replies=5](http://wordpress.org/support/topic/132824?replies=5)
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/comment_author_url/#post-613078)
 * Then one should be ditched… closed…

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘comment_author_url’ is closed to new replies.

 * 8 replies
 * 3 participants
 * Last reply from: [moshu](https://wordpress.org/support/users/moshu/)
 * Last activity: [18 years, 9 months ago](https://wordpress.org/support/topic/comment_author_url/#post-613078)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
