Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Im trying to create shortcodes for Twitter Bootstrap Collapse.

This is what Im trying to achieve:

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

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) {  
    extract(shortcode_atts(array(  
    '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>
         <div id="'.$accordion.'" class="accordion-body collapse in">
            <div class="accordion-inner">"'.$content.'"</div>
         </div>
        </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.

share|improve this question
    
possible duplicate of Twitter Bootstrap Use Collapse in Custom Post Type –  Brian Fegter Oct 15 '12 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 Oct 15 '12 at 16:10
    
Please add to your question details about "server error" part. What are actual error messages appearing and such. –  Rarst Oct 15 '12 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 127.0.0.1/wordpress. 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 Oct 16 '12 at 7:56
    
Please enable debug output and see if that makes any error messages appear. –  Rarst Oct 16 '12 at 19:38

1 Answer 1

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

share|improve this answer
    
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 Oct 20 '12 at 20:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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