Support » Plugins » Hacks » comment_author_url()

  • Resolved Peter_L



    I have a post which has a custom wp_list_comments(). Works fine.

    I wanted to add a custom comment field but couldn’t make it work.
    So, I’m using the default url field as a custom field (city).

    <li class="comment-form-url">' .
                    '<label for="url">City *</label>' .
                    '<input id="url" name="url" type="text" value="" />' .

    Works fine, but when I call out the comment fields, the url-city value, called with comment_author_url() displays like this http://value.
    So, if somebody put in Brussels, it will display as http://Brussels
    Obviously, I want the http:// gone.

    How do I solve this in php? I already tried this:
    <?php echo substr(comment_author_url(),7); ?>
    But wordpress just ignores the extra php and prints the value as if I had put in
    <?php echo comment_author_url(); ?>
    I’d rather not fiddle around in the core files either.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael


    Forum Moderator

    try to use get_comment_author_url() in your code:

    <?php echo substr(get_comment_author_url(),7); ?>

    the difference is that the function starting with get_ returns the value to be used, instead of putting it out to the screen.

    It works.

    I actually just found another solution to this problem.
    Adding this line to your functions.php

    function striphttp($text){$return = str_replace('http://', '', $text); return $return;}
    add_filter('comment_url', 'striphttp');

    Works as well. (it’s based on the code to remove the rel=”nofollow” attribute)
    But thinking about it, this will probably remove the http on all comment_author_url ‘s instead of just on the one post.

    So, I’m just gonna use the solution with the get_ version.

    Thanks for the help alchymyth.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘comment_author_url()’ is closed to new replies.