WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] comment_author_url() (3 posts)

  1. Peter_L
    Member
    Posted 3 years ago #

    Hello,

    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="" />' .
    '</li>'

    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.

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    try to use get_comment_author_url() in your code:

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

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

  3. Peter_L
    Member
    Posted 3 years ago #

    It works.

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

    <?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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.