Search code examples
wordpressshortcodewordpress-shortcode

Why does my shortcode wrap injected text with quotes?


In my Wordpress site I'm building a plugin that injects a shortcode into a page. When I view the page it just shows the code of the shortcode:

[learndash_course_grid skin='grid' card='grid-2' thumbnail_size='large' post_meta='false' taxonomies='ld_course_tag:"Emergency Preparedness"']

When I view page source I see that the shortcode code is wrapped in double-quotes, so the page is just rendering it as a text string. If I put the shortcode into a page manually, it executes the shortcode correctly, so I know the shortcode itself is valid.

Is there a way to have that not happen, so the shortcode can actually execute?


Solution

  • You should have a look at the do_shortcode function. You can find a documentation here.

    You can call the shortcode like this from your php code:

    echo do_shortcode( '[learndash_course_grid skin="grid" card="grid-2" thumbnail_size="large" post_meta="false" taxonomies="ld_course_tag:'Emergency Preparedness'"]' );