简体   繁体   中英

Add do_shortcode to printf in WordPress child theme

I'm trying to make a 'Copyright text' Customizer field render shortcodes.
The field is rendered via footer.php so I can override the original code in my child theme.
The code uses printf that fetches the content input from a field in Customizer options like so:

<?php printf( wp_kses_post(__( '%s', 'slim' )), Slim_Opt::getOption( 'footer_copyright_text', 'Slim - eCommerce WP Theme' )); ?>

I've tried adding do_shortcode around wp_kses_post as well as around the whole contents of printf , but it didn't work.
I've tried replacing printf with echo do_shortcode , but it didn't work either.

Is there a way to keep this code for retrieving the setting value from Customizer and also rendering any shortcodes that might be within that value?

In order for the shortcode to work, it needs to be processed first from the customizer option - or you can just output the option using do_shortcode

  1. No variable option:
echo do_shortcode( Slim_Opt::getOption( 'footer_copyright_text', 'Slim - eCommerce WP Theme' ) );
  1. Or, you can hold the output in a variable:
<?php $footer_option = do_shortcode( Slim_Opt::getOption( 'footer_copyright_text', 'Slim - eCommerce WP Theme' ) ); 
printf( wp_kses_post(__( '%s', 'slim' )), $footer_option ); ?>

Either way works, just depends on if you want it to pass to wp_kses_post() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM