只是[link to= "https://wordpress.stackexchange.com/"].
这是一个教科书上的例子extract() 很糟糕。你很难分辨变量是从哪里来的。extract() 从数组中创建变量,键成为变量名。所以这部分:
extract(shortcode_atts(array(
"to" => \'http://net.tutsplus.com\'
), $atts));
正在创建具有
to 键,设置为
http://net.tutsplus.com 如果未在中定义
$atts. 那就是
extract()ed,以便
to 密钥变为
$to.
您应该避免使用extract() 只需使用$atts 变量:
function link($atts, $content = null) {
$atts = shortcode_atts(array(
"to" => \'http://net.tutsplus.com\'
), $atts);
return \'<a href="\'.$atts[\'to\'].\'">\'.$content.\'</a>\';
}