我想知道这个函数的目的是什么:shortcode_ats
因为可以这样写:
$a = shortcode_atts( array(
'Title' => 'Title'
), $atts );
或不使用此函数:
$a = $atts['Title'] ? $atts['Title'] : "";
所以我想知道我什么时候应该使用shortcode_ats函数?
WordPress包含许多过滤器,允许各种插件做诸如调整或本地化之类的事情。
shortcode_atts()
函数应用过滤器。只是摆弄一个数组就不行。https://codex.wordpress.org/Function_Reference/shortcode_atts Change_Log
而且,有时核心开发人员会更改数据结构。如果你使用这些函数,你的软件就不会在它们这样做的时候崩溃。
-
这里简单的函数 shortcode_ats 用来覆盖传递的shortcode参数参数。
-
如果您通过shortcode传递参数,则它将自动应用shortcode_ats数组变量key与您通过shortcode传递的参数/参数。
-
它将覆盖与短码相关的功能,例如
-
[new_shortcode id = ' 123 ']
);
function do_task(){
$atts = shortcode_atts( array(id=>''), 'new_shortcode');
}
?>