Skip Navigation

[Resolved] Short codes do not work in WYSIWYG fields

This thread is resolved. Here is a description of the problem and solution.

Problem: I have added some shortcodes inside a WYSIWYG custom field. I would like to output the results using get_post_meta, but the shortcodes are not executed. They are just written out in the content of the field.

Solution: The WordPress function get_post_meta retrieves raw data from the database, but does not execute any shortcodes in that content. So the behavior you're experiencing is expected, if not what you're trying to accomplish. Take a look at the WordPress API "do_shortcode()".

$field = get_post_meta(get_the_ID(), 'wpcf-extra-text-under-products', true);
echo do_shortcode($field);

Or you can try applying filters to that field value like so:

echo apply_filters('the_content', get_post_meta(get_the_ID(), 'wpcf-extra-text-under-products', true));

Relevant Documentation: https://developer.wordpress.org/reference/functions/do_shortcode/

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 6 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#615942

I'm trying to show a youtube movie and a slider (smart slider 3) in a WYSIWYG field created using WP-types, but instead of a movie or slider, only the short code is displayed. Both short codes works fine in the native WP content field. Any hints?

#616121

Hi, can you tell me how the WYSIWYG field is added to the page? What shortcode are you using to insert the field, and where have you placed it? Are you looking at the single post, a View of posts, or an archive on the front-end?

Temporarily disable all plugins except Types, Views, and the Slider plugin. Activate a default theme like Twenty Seventeen, and test again. Is the shortcode still printed out on screen? If not, please reactivate your parent theme, child theme, and other plugins one by one until the conflict is revealed.

#616246

Hi Christian,

Thank you for your answer.

It is a quite simple setup where I output the WYSIWYG field to the page trough the following php-code added to a native WP template. I'm not using Views in this relation.

 echo get_post_meta(get_the_ID(), 'wpcf-extra-text-under-products', true); 

The issue persist when I use standard theme Twenty Seventeen and have deactivated all plugins except Toolset Types and Smart Slider 3.
Looking forward hearing from you again ?

#616437

The WordPress function get_post_meta retrieves raw data from the database, but does not execute any shortcodes in that content. So the behavior you're experiencing is expected, if not what you're trying to accomplish. Take a look at the WordPress API "do_shortcode()" here: https://developer.wordpress.org/reference/functions/do_shortcode/

$field = get_post_meta(get_the_ID(), 'wpcf-extra-text-under-products', true);
echo do_shortcode($field);

Or you can try applying filters to that field value like so:

echo apply_filters('the_content', get_post_meta(get_the_ID(), 'wpcf-extra-text-under-products', true));