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

10 comments
  • Hi,

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

    Regards,
    Tom

    • 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?

  • Hi Ricard,

    I’ve tried adding many [thumbs-rating-buttons] in a single post or 1 post about 20 [thumbs-rating-buttons] and when I test it the results were the same on all Thumbs Rating in a single post or content. Any idea how do I do this? Thanks in advance

    • Hey Mike,

      Sorry for the late response, your comment fell into the spam folder.

      Not sure I get your issue. You have to consider the thumbs-rating plugin I wrote ( https://wordpress.org/plugins/thumbs-rating/ ) has to be linked to a single post or content.

      You can not add multiple buttons on the same post and expect the user to vote diferent things. Each button has to be linked to a post or custom post type.

      Let me know if this helps.

      Ricard

  • Hi, Same basic question. Is there a way to pass in a postID to the shortcode? I have a list of CPT results on a page and i need a way to have thumbs up/down on each one with AJAX updates. If there is a way to pass in the postID then i can use it in the loop.

  • Hey Tom,

    For anyone reading this, the context is this plugin https://wordpress.org/plugins/thumbs-rating/

    At this moment, for the current version, there’s no way to pass the post ID to the buttons shortcode.

    Best regards.

  • Would this be something you could add easily or do i need to build something myself? I have to launch this feature soon.

    • Tom

      I have no time to add new features. The plugin is stable enough and rather super simple.

      Have you considered a more robust/complete rating plugin?

      Cheers.

Leave a Reply

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

*
*