WordPress短代码功能提供白页

时间:2015-04-25 11:20:11

标签: php wordpress

我正在为自己的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标签之间将它添加到我的functions.php时,当我输入任何WordPress页面时,它会给我一个白页。所以wp-admin和普通页面都是白色的。

我将它添加到functions.php和底部。都没有奏效。有人能解释我为什么会这样做吗?

2 个答案:

答案 0 :(得分:0)

请使用此代码......

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");

link是默认关键字,因此您无法使用链接。

我希望你能得到。

答案 1 :(得分:0)

根据comments中的代码:

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");
相关问题