0

I want 2 buttons in my blog post. One is "DEMO" and another one is "DEWNLOAD" . For Demo button shortcode I use this codes.

function demo_button($atts,$content = null) {
    extract( shortcode_atts( array(
          'url' => '#'), $atts ) );
return '<a href="'.$url.'" class="btn btn-default btn-demo">' . do_shortcode($content) . '</a>';
}

add_shortcode('demo'.'demo_button')

It works fine in my site.. when I add download button in the same way the wordpress dashboard got white.Download button code

function download_button($atts, $content = null) {
 extract( shortcode_atts( array(
          'url' => '#'
), $atts ) );
return '<a href="'.$url.'" class="btn btn-default btn-download">' . do_shortcode($content) . '</a>';
}
add_shortcode('download', 'download_button');

I dont know Why.. I am new in wordpress and PHP.. SO please help me out. Thanks in advance

1

If I enter this shortcode:

[download url="http://example.com"]Download[/download]

it works fine. But you have to enter the link text as content yourself. You might have missed that, the way I read your question.

Your [demo]-Shortcode throughs an error. To see this, you need to have WP_DEBUG set to true:

 Notice: Undefined variable: func in \wp-includes\shortcodes.php on line 92

This is because, your code says

add_shortcode('demo'.'demo_button');

This in fact creates an shortcode like [demodemo_button] with no function attached. Use a comma instead the point:

add_shortcode('demo','demo_button');

If you do so, it works fine too. But again, you have to add the link text as content, like here:

[demo url="http://example.com"]Linktext[/demo]

If you want a fixed link text, you should have a look into this code snippet:

function download_button($atts, $content = null) {
 extract( shortcode_atts( array(
          'url' => '#'
 ), $atts ) );
 return '<a href="'.$url.'" class="btn btn-default btn-download">Download</a>';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.