How to Use Shortcodes in Custom Fields
read more

How to Use Shortcodes in Custom Fields


The default custom fields meta box provided by WordPress strips out shortcodes from custom field values. This trick shows you how to use the WordPress do_shortcode() function to get around this.

I saw this posed on the StudioPress support forums and it’s a very good question. The default custom fields meta box provided by WordPress strips out shortcodes from custom field values. This means you cannot, by default, use shortcodes within the values of your custom fields. For example, say you want to use a Gravity Forms shortcode to output a form in a custom field. WordPress will not render this shortcode.

Fortunately, there’s a small trick you can use to solve this: the do_shortcode() function. By running values through do_shortcode(), it tells WordPress to render shortcodes as it would if you inserted the shortcode in the content editor (because the content added within the editor is passed through this very function). Here’s an example: