Modify or Filter Comment Text in WordPress

I am working on a plugin to automatically modify the comments’ texts based on the inputs provided by the commentator. The basic requirements of the plugin is to show social links of the commentator and give them a conditional do-follow link depending on their contributions (total number of approved comments) to the blog. There are actually some free plugins available which you can use, but you have to combine at least 4 of them to get the whole functionality of the plugin I am coding. The plugin itself a bit tricky, but I going to show you an easier version of it.

Gearing Up

I hope you already know how to add custom fields in comment form and save the input value in database, if not, I strongly recommend you to read How To Add Custom Fields In WordPress Comment Form. I am going to use the same code for this.

/* Adds The Field */
function comment_twitter_field() { ?>
	

Now that we have added a field to enter the twitter ID of the commentator, we are going to show it after the comment texts in their comment.

The Hook

The hook that processes the texts in comments id comment_text. We are going to add a filter at this and show the values of our custom fields.

function show_twitter($comment) {
	$comment_twitter = get_comment_meta( get_comment_ID(), 'comment_twitter', true );
	$comment_author = get_comment_author();
	if ( $comment_twitter ) {
		$comment .="

"; $comment .= "$comment_author's Twitter: 4df189ce  "; $comment .= "

"; } return $comment; } add_filter( 'comment_text', 'show_twitter' );

Here is the full code if you want to implement it right away. Copy the code and paste it in your theme’s functions.php file. Alternatively, if you want to use it as a plugin, just create a new php file, paste the code there and upload it in the plugins folder. You can then activate or deactivate it at your will.


	

6d012db4Twitter:b9b43016

"; $comment .= "$comment_author's Twitter: 4df189ce"; $comment .= "

"; } return $comment; } add_filter( 'comment_text', 'show_twitter' ); ?>

That will help you to get started..

Get Updates In Your Inbox

Get the WordPress Tips and latst Internet Marketing ideas delivered directly to your email inbox, plus access to our FREE Pro Blogging Model blogging guide.

You need to confirm your email once. Don't worry, we hate SPAMs as much as you do

Comments

  1. says

    What a fantastic idea! I am all for giving something back to the people who take the time to comment on my blog. I won’t try and do the tutorial that you have laid out above because I always mess things up, I will certainly be looking out for your finished plugin though, hopefully the price won’t be too steep. :)

Speak Your Mind

Your email address will not be published. Required fields are marked *

You may use these HTML Tags and Attributes

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>