shortcode_atts()函数是与wordpress短代码函数:add_shortcode()一起使用的,结果返回短代码中的属性系列数组。
- <?php shortcode_atts( $pairs , $atts ); ?>
$pairs
(array) (必须) 所有支持的属性和他们默认值的完整列表。
默认: None
$atts
(array) (必须) 用户在短代码标签中输入的属性值
默认: None
(array)
用户输入和默认两者合并和过滤之后的数组列表。
在你主题的functions.php文件添加如下代码
- function bartag_func($atts) {
- extract(shortcode_atts(array(
- 'foo' => 'no foo', //默认为no foo
- 'bar' => 'default bar'//默认为default bar
- ), $atts));
- return 'bartag: ' . $foo . ' ' . $bar;
- }
- add_shortcode('bartag', 'bartag_func');
编辑文件时切换到文本模式添加如下短代码:
- [bartag foo="koala" bar="bears"]
输出内容如下:
bartag: koala bears
shortcode_atts() 位于 wp-includes/shortcodes.php.
相关函数:add_shortcode()