1

Is there a way to enable shortcodes in text saved in the customizer and retrieved using get_theme_mod?

I'm guessing there's a filter in a similar manner to enabling shortcodes in widgets.

3

To enable shortcodes in text widgets add a filter like that:

add_filter( 'widget_text', 'do_shortcode' );

You can pass every string to do_shortcode() including get_theme_mod() calls.

echo do_shortcode( get_theme_mod( 'theme_setting' ) );
  • Sorry, to clarify I have a textarea input in the customizer which stores some "about us" text. I'd like to give the user the ability to use shortcodes in this text which, when echoed in the template, would process the shortcode. – mistertaylor Apr 27 '16 at 14:54
  • The second snippet will do what you need - just replace theme_setting with the name of your "about us" text setting. – TheDeadMedic Apr 27 '16 at 14:55
  • Yes, that should work. You wrote you use get_theme_mod(), that's why I gave you that example. – Zlatev Apr 27 '16 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.