You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 05:57:21