简体   繁体   English

在WordPress子主题中将do_shortcode添加到printf

[英]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. 该字段通过footer.php呈现,因此我可以覆盖子主题中的原始代码。
The code uses printf that fetches the content input from a field in Customizer options like so: 该代码使用printf来从Customizer选项中的字段中获取内容输入,如下所示:

<?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. 我试过在wp_kses_post以及printf的全部内容周围添加do_shortcode,但这没有用。
I've tried replacing printf with echo do_shortcode , but it didn't work either. 我试过用echo do_shortcode替换printf,但是它也不起作用。

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? 有没有一种方法可以保留此代码,以便从Customizer检索设置值并呈现可能在该值内的任何短代码?

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 为了使shortcode起作用,需要先通过定制程序选项对其进行处理-或者您可以使用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() . 无论哪种方法,都取决于您是否希望它传递给wp_kses_post()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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