WordPress.org

Support

Support » Themes and Templates » comment_author_url

comment_author_url

  • Hi,
    I am adding this piece of code to my blog

    “><?php comment_author(); ?>

    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)
  • woops i guess i didn’t escape my characters
    here it is again, kind of!

    “><?php comment_author(); ?>

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

    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

    @whooami

    Member

    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>

    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

    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

    @whooami

    Member

    the OP has two threads going on this:

    http://wordpress.org/support/topic/132824?replies=5

    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.