Im trying to create shortcodes for Twitter Bootstrap Collapse.

This is what Im trying to achieve:

  [collapse accordion="#accordionOne" title="my heading1"]some text[/collapse]
  [collapse accordion="#accordionTwo" title="my heading2"]some more text[/collapse]

So for example 'my heading1' would show and 'some more text' would be collapsible.

Here is the code Im using, the last shortcode [collapse] is causing a server error on my local install.

function collapse-group( $atts, $content = null ) {  
return '<div class="accordion" id="accordion2">"'.$content.'"</div>';  
add_shortcode("collapse-group", "collapse-group");

function collapse($atts, $content = null) {  
    'accordion' => '',
    'title' => ''  
    ), $atts));  

return '<div class="accordion-group">
        <div class="accordion-heading">
        <a class="accordion-toggle" data-toggle="collapse" 
        data-parent="#accordion2" href="'.$accordion.'">"'.$title.'"</a>
         <div id="'.$accordion.'" class="accordion-body collapse in">
            <div class="accordion-inner">"'.$content.'"</div>

add_shortcode("collapse", "collapse");

I know there are plugins but I'd prefer to have this custom made for this specific instance so I don't have to rely on a plugin with all sorts of other bloat. Im hoping an answer to this question would be useful to others.

  • possible duplicate of Twitter Bootstrap Use Collapse in Custom Post Type Commented Oct 15, 2012 at 15:15
  • After the answer from my previous question I realised I would need to use shortcodes, so I tried to create them as above but I got stuck. I'm sorry that you think this is a duplicate. I looked through the posts tagged shortcode and didn't really find anything to help me. This was helping me to get this far wp.tutsplus.com/tutorials/theme-development/…
    – stemie
    Commented Oct 15, 2012 at 16:10
  • Please add to your question details about "server error" part. What are actual error messages appearing and such.
    – Rarst
    Commented Oct 15, 2012 at 21:27
  • Im running a local install using bitnami stack in Windows. I get the following error "Server error The website encountered an error while retrieving It may be down for maintenance or configured incorrectly." When I remove the shortcode above from functions.php the error does not occur. I thought perhaps there was something wrong with my return function.
    – stemie
    Commented Oct 16, 2012 at 7:56
  • Please enable debug output and see if that makes any error messages appear.
    – Rarst
    Commented Oct 16, 2012 at 19:38

1 Answer 1


use do_shortcode($content) instead of $content in first function(collapsegroup)

  • That allows me to show the elements but the javascript is not working. The link for the title /?p=34558#collapseOne does not open to show the content as it does when I used the code from bootstrap site.
    – stemie
    Commented Oct 20, 2012 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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