如何在Storefront主题的customads1、customads2 div中添加短代码?
解决方案
要实现将两个customads容器内的内容替换为指定短代码,你需要使用WordPress内置的do_shortcode()函数来解析短代码(直接输出短代码文本不会被WordPress处理)。修改后的完整代码如下:
add_action( 'storefront_footer', 'fuyn_footer_widgets', 11 ); function fuyn_footer_widgets(){ if( is_checkout() ){ global $woocommerce ; if ( $woocommerce->cart->total != 0 ) { return; } echo '<div class="customads" style="width: 100%;display: flex;"> <div class="customads1" style="width: 50%;background: bisque;margin: 5px;">' . do_shortcode('[sc name="ads"][/sc]') . '</div> <div class="customads2" style="width: 50%;background: bisque;margin: 5px;">' . do_shortcode('[sc name="ads"][/sc]') . '</div> </div>'; } }
关键修改说明
- 将原代码中两个div内的
Shortcode.文本替换为do_shortcode('[sc name="ads"][/sc]') - 通过
do_shortcode()函数,WordPress会自动解析并执行指定的短代码,生成对应的内容插入到div容器中
内容的提问来源于stack exchange,提问作者marwah
相关产品推荐
相关产品推荐

