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' );
Code language: JavaScript (javascript)
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' );
Code language: JavaScript (javascript)
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');
Code language: JavaScript (javascript)
Just wanted to say thanks for the code!
You’re welcome, Tim!
Hi Rick, is add_filter( ‘comment_text’, ‘do_shortcode’ ); secure for a website?
Hey Jose,
I don’t see why not. In the end you as the site owner have the power to restrict, add or remove functionality.
Sure, perhaps you have a plugin that shows sensitive information via shortcodes. Enabling shortcodes in comments means someone could potentially output information you don’t want.
There are 2 other filters that perhaps help with your concerns:
https://developer.wordpress.org/reference/hooks/pre_do_shortcode_tag/
https://developer.wordpress.org/reference/hooks/do_shortcode_tag/
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.
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.
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.
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
¡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?
Hola,
Si hablas del Thumbs Rating plugin, ya lo hace.
Mira el FAQ, al final tienes el shortcode que genera listas en base a parámetros:
https://wordpress.org/plugins/thumbs-rating/faq/
Un saludo.
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).