Allow Shortcode in Theme Customizer

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…

Solutions Collecting From Web of "Allow Shortcode in Theme Customizer"

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

@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.

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.