我正在为我自己的WordPress主题创建一个简码。我创建了这个:
function link($atts, $content = null) {
extract(shortcode_atts(array(
"to" => 'http://net.tutsplus.com'
), $atts));
return '<a href="'.$to.'">'.$content.'</a>';
}
add_shortcode("link", "link");
但是当我把它添加到我的函数中时.php在打开和关闭PHP标签之间,当我进入任何WordPress页面时,它会给我一个白页。所以wp-admin和普通页面都是白色的。
我将其添加到函数顶部.php底部。两者都没有用。有人可以解释为什么我会得到这个吗?
请使用此代码...
function mylink($atts, $content = null) {
extract(shortcode_atts(array("to" => 'http://net.tutsplus.com' ), $atts));
return '<a href="'.$to.'">'.$content.'</a>';
}
add_shortcode("mylink", "mylink");
链接是默认关键字,因此您不能使用链接。
我希望你会得到。
在注释中加入您的代码:
function infobutton($atts, $content = null) {
extract(shortcode_atts(array("tekst" => 'Meer informatie' ), $atts));
return '<div class="container extend"> <h2 class="center">'.echo $content.' <a href="pakket" class="button-orange-small">'.echo $tekst.'</a></h2> </div>';
}
add_shortcode("infobutton", "infobutton");
返回值时不需要使用 echo,它应该是这样的:
function infobutton($atts, $content = null) {
extract(shortcode_atts(array("tekst" => 'Meer informatie' ), $atts));
return '<div class="container extend"> <h2 class="center">'.$content.' <a href="pakket" class="button-orange-small">'.$tekst.'</a></h2> </div>';
}
add_shortcode("infobutton", "infobutton");