我只是创建这样的短代码:
add_shortcode( 'demo1', 'demo1_init' ) );
add_shortcode( 'demo2', 'demo2_init' ) );
function demo1_init() {
// Shortcode Def. here...
}
function demo2_init() {
// Shortcode Def. here...
}
如何使用过滤器动态创建这些短代码?像这样的东西。 E.g。
$a = array(
"demo1" => "demo1_init",
"demo2" => "demo2_init",
);
答案 0 :(得分:0)
以下内容应该完成工作
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" );