Add shortcode support to comments

iThemes Security Review - banned users

Adding this snippet to the functions.php of your wordpress theme will enable shortcodes for comments. This code will first remove all shortcodes when it gets to comments and reinitialize only the shortcodes listed within init_common_shortcodes function. I have added in a simple sample shortcode that will grab the users website url and replace the [mysite] shortcode.

function init_common_shortcodes() {
  // add each shortcode you want enabled in comments
  add_shortcode('mysite', 'mysite');
function init_comment_shortcodes() {
  add_filter('comment_text', 'do_shortcode');
add_filter('comments_template', 'init_comment_shortcodes');
function mysite(){
	return '<a href="' .get_comment_author_url(). '">(My website)</a>';
add_shortcode('mysite', 'mysite');

Comments  Leave a Reply

  1. Will you consider making it as a plugin?

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!