WordPress shortcode function gives white page

I’m creating a shortcode for my own WordPress theme. I created this:

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

But when I add this to my functions.php between opening and closing PHP-tags, it gives me a white page when I enter whatever WordPress page. So wp-admin and normal pages are all white.

Read More

I added it on top of functions.php and at the bottom. Neither worked. Can somebody explain why I get this?

Related posts

Leave a Reply

2 comments

  1. Please use this code…

    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 is default keyword so you can not use link.

    i hope you will get.

  2. Accrording to your codes in 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");
    

    You don’t need to use echo while you returning the value, it should be like this:

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