Remove link to comment authors website from wordpress Comments

PUBLISHED ON Fri 8, 2008 | POSTED IN Internet, What I learnt

Are you tired of moderating, removing or editing the URLs of people who post comments in your wordpress blog? Are you sick of all the comment spammers who post those cookie cutter comments using scripts in your blog just to post links in your blog via the comment links to comment authors site? Well I was! And that’s when I decided that I would hack the wordpress code a little bit to totally disable linking to commenter’s site from the comments posted in the blog.

The link to commenter’s site does serve some good purposes like letting the comment poster link to his/her blog/site which might have good resources and also allows free publicity and exchange of traffic between genuine blogs and sites via the comment links, but there is way too much nuisance and problems which weigh down these advantages.

Well this is what you need to do if you want to remove these links. Go to the wp-includes directory in your wordpress installation via ftp, locate a file called comment-template.php (in older versions of wordpress you would need to find comment-functions.php) , download the file, create a backup of the file to make sure you can upload a working copy in case you mess up.
Open the php file with notepad (any text editor) or any code editing software you may have. Now in the file at around line 106 you would locate a function called get_comment_author_link() (around line 347 if you are editing comment-functions.php) . The line number might vary from wordpress versions, but the code within the function is the same for all versions of wordpress after 1.5, so this hack will work for all versions of wordpress 1.5 and up. Within the function you would see the following lines
[sourcecode language=’php’]
$url = get_comment_author_url();
$author = get_comment_author();
if ( empty( $url ) || ‘http://’ == $url )
$return = $author;
$return = “$author“;
return apply_filters(‘get_comment_author_link’, $return);

What this function does is, check if the comment author posted a URL when he/she posted a comment, if there is no url it just prints the author name, if there is an URL with the comment then wordpress prints the author’s name as a link to the author’s website. We are going to modify the function to just print the author’s name (without a link) even if a URL is present with the comment. For that just replace
[sourcecode language=’php’]
$return = “$author“;
[sourcecode language=’php’]
$return = $author;

And you are done! Just save the file, upload the file back into the server and you should get comments with links removed with just the author’s name throughout the website!

Next I am going to try to totally remove the URL field while posting comments into the blog to save the hassle of commenter’s entering a URL. Will get back with a quick guide for that when I succeed.



This entry has 11 comments . If you like, you can add a comment.





warren farrell





iill net