WordPress.org

Ready to get started?Download WordPress

Forums

[closed] comment_author_url (9 posts)

  1. andyb2
    Member
    Posted 6 years ago #

    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

  2. andyb2
    Member
    Posted 6 years ago #

    woops i guess i didn't escape my characters
    here it is again, kind of!

    "><?php comment_author(); ?>

  3. andyb2
    Member
    Posted 6 years ago #

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

  4. andyb2
    Member
    Posted 6 years ago #

    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

  5. whooami
    Member
    Posted 6 years ago #

    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>
  6. andyb2
    Member
    Posted 6 years ago #

    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

  7. moshu
    Member
    Posted 6 years ago #

    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.

  8. whooami
    Member
    Posted 6 years ago #

    the OP has two threads going on this:

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

  9. moshu
    Member
    Posted 6 years ago #

    Then one should be ditched... closed...

Topic Closed

This topic has been closed to new replies.

About this Topic