How to allow shortcodes in WordPress comments

Shortcodes in Comments

WordPress comments as far as I know don't render shortcodes.

If your theme use custom shortcodes you can't use them in comments. Also, with the new video and audio support for WordPress 3.6 you can not use them in comments.

Simply add this line to your functions.php of your theme and now shortcodes will be correctly rendered within comments.

add_filter( 'comment_text', 'do_shortcode' ); 

Shortcodes in Widgets

Yes, following the same principle you'll need to add a new filter to the functions.php file.

Try it first, put a shortcode in a text widget, your theme might already have this line. If the shortcode doesn't work, then paste the following snippet:

add_filter( 'widget_text', 'do_shortcode' ); 

Shortcodes in Excerpt

Yep. Even though I wouldn't recommend it. You see, I usually use this field for SEO purposes so I won't use any shortcodes in it.

However, if you need it, here it is:

add_filter( 'the_excerpt', 'do_shortcode');

About Ricard Torres

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast

  • Hi,

    Could you please inform us about the way to allow shortcodes in wordpress search results?


    • Hi Tom,

      Do you mean when you use the WordPress search?

      Well, that should be within the search.php file of your theme. If the theme prints the whole post, an excerpt or just the title.

      I’m not sure it’s something you can turn on from the functions.php file (like the examples above).

  • ¡Hola Rick!

    Edu plugin es excelente pero me encantaría que en el plug in también pudiéramos ordenar las entradas ya sea “Con más pulgares arriba” y “más pulgares abajo”. Creo que ayudaría a muchos blogs a generar competitividad entre sus autores.

    ¿Qué opinas?

Leave a Reply

Add <code> Some Code </code> by using this tags.