Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is probably really simple, but I just can't figure it out. So I change the input form on my comment form php. The changed snipped looks like this:

http://pastebin.com/3Mj1XHGJ

Yet when somebody doesn't click on "Website" at all, still a "http://Website" link will be generated for some. Is there any way to make it so that there won't be any url display if they haven't inserted a website url at all? Right now only when I click on the "Website input" textarea and make the "Website" text actually disappear it works.

(The following is just a side question and I'm also not sure if it's okay to ask this, so you might as well ignore this): I also wanted to insert little icons in front of the text (before Website, Mail etc.) I know how to do it (just as background image using the stylesheet), but I'm already using a background image and I was wondering if there's another way round as using two background images won't work. Probably I have to rewrite the comment.php a bit instead, but I don't think it's possible to insert a "img src" into the input command?

My website is here.

Thanks a lot in advance! :D

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Try adding the code to the comment-template.php file located in wp-includes, right under the

function get_comment_author_link( $comment_ID = 0 ) {
/** @todo Only call these functions when they are needed. Include in if... else blocks */
$url    = get_comment_author_url( $comment_ID );
$author = get_comment_author( $comment_ID );

if ( empty( $url ) || 'http://' == $url )
    $return = $author;
else
    $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
return apply_filters('get_comment_author_link', $return);
}

so that the final result looks like this:

function get_comment_author_link( $comment_ID = 0 ) {
/** @todo Only call these functions when they are needed. Include in if... else blocks */
$url    = get_comment_author_url( $comment_ID );
$author = get_comment_author( $comment_ID );

if ( empty( $url ) || 'http://' == $url )
    $return = $author;
else
    $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
return apply_filters('get_comment_author_link', $return);
}
add_filter('pre_comment_author_url', 'filter_comment_url');
function filter_comment_url($url){
if ($url == "Website" || $url == "http://Website"){
    $url = '';
}
return $url;
}
share|improve this answer
    
Thank you very much for trying to help. I tried, but it didn't work. Actually now the comment of a person will only be posted if they also enter a website, if not the comment won't go through. I deleted the snippet again, but the error now still occurs. Any ideas how to fix that? –  japanworm Aug 26 '11 at 1:33

you can use the pre_comment_author_url filter hook to clear the url if its Website :

add_filter('pre_comment_author_url', 'filter_comment_url');
function filter_comment_url($url){
    if ($url == "Website" || $url == "http://Website"){
        $url = '';
    }
    return $url;
}

as for images/icons its strictly a CSS issue and FYI you can simply insert the icons as html img tags.

share|improve this answer
    
Hello. Thank you for your answer. I added the filter hook into my function.php, but I still have exactly the same problem?! –  japanworm Jul 13 '11 at 2:47
    
Hello! I'm still desperately looking for a solution. The one above didn't work for me. I put it into my function.php, was that correct? Do I have to add anything else to my comment.php, too? Please help. Thanks –  japanworm Jul 17 '11 at 14:59
    
This is an example!!! Change the case specific to match yours and you should be fine. –  Bainternet Jul 17 '11 at 16:20
    
Sorry, I'm a complete beginner, so I'm not sure which of these I actually CAN change. Thanks. –  japanworm Jul 20 '11 at 13:37
2  
@Bainternet don't you want to run that check on pre_process_comment hook, after the comment form is submitted? The pre_comment_author_url fires when the form is generated, not when it is submitted. –  Chip Bennett Sep 2 '11 at 0:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.