All theme dev who follows the wp guidelines properly, now uses ability of default wp customizer to customize their themes, instead of making a different theme option section the admin panel.

But what I was unable to figure out is that how to use shortcode within that wp customizer.

For example: In one of the theme I saw a section in the customizer called copyright text. Now I could manually put Copyright 2016, but what I wanted to do is to take advantage of wp shortcode. So I created a simple shortcode called year to auto fetch the current year.

add_shortcode('year', function() {
    return date( 'Y' );

But when I use [year] within wp customizer, it doesn't recognize the shortcode. I know there is a way to enable shortcode for widget area, but I was thinking if there is something similar for the wp theme customizer are too.

Any help will be great...

3 Answers 3


wrap whatever you are outputting the shortcode in around do_shortcode()

  • Hi, sorry for the late reply. So, within the wp customizer text field, you want me to use do_shortcode('[year]') or do you want me to use <?php do_shortcode('[year]') ?>. Which one? Please let me know...
    – iSaumya
    Commented Jan 12, 2016 at 16:54
  • It's not working buddy. I've tried every possible thing, not working. Here is what I've tried <?php echo do_shortcode('[year]'); ?> - showing nothing
    – iSaumya
    Commented Jan 12, 2016 at 17:05

@setterGetter is right, you need to wrap it with do_shortcode() but you need to do it where the customizer field is called not inside the field within the customizer. In your case try looking in footer.php then if you're able to find where they output the code wrap it with echo do_shortcode()

But that doesn't mean your shortcode will display properly, you also need to consider what type of sanitize_callback they used when they create that customizer setting. It might happen that they use some sanitize callback that will prevent your shortcode to run.

  • Yes you are right. I've checked and they do use sanitize_callback.
    – iSaumya
    Commented Feb 2, 2016 at 17:42

Kirki customizer plugin seems to have a type 'code' control which appears to accept shortcodes and output them out raw through the get_theme_mod()

you will need to learn a bit of how to integrate the plugin into your theme.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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