【问题标题】:How to use filter to dynamic shortcodes?如何对动态短代码使用过滤器?
【发布时间】:2014-11-17 14:38:49
【问题描述】:

我只是创建这样的短代码:

add_shortcode( 'demo1', 'demo1_init' ) );
add_shortcode( 'demo2', 'demo2_init' ) );

function demo1_init() {
   // Shortcode Def. here...
}

function demo2_init() {
   // Shortcode Def. here...
}

如何使用过滤器动态创建这些短代码?像这样的东西。例如

 $a = array(
        "demo1"       =>  "demo1_init",
        "demo2"       =>  "demo2_init",
);

【问题讨论】:

    标签: wordpress filter shortcode


    【解决方案1】:

    以下应该可以完成工作

    function demo1_init() {
        // Shortcode Def. here...
        return "demo1";
    }
    
    function demo2_init() {
        // Shortcode Def. here...
        return "demo2";
    }
    
    function register_shortcodes() {
    
        $shortcodes = array(
            "demo1"   =>  "demo1_init",
            "demo2"   =>  "demo2_init",
        );
    
        foreach($shortcodes as $shortcode => $func) {       
            add_shortcode($shortcode, $func);
        }
    
    }
    add_action( "init", "register_shortcodes" );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-20
      • 1970-01-01
      • 1970-01-01
      • 2021-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      相关资源
      最近更新 更多