WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Pastebin of the html prototype and my attempt at the wp function -> http://pastebin.com/91zBv8sk

I want a simple notation so its easy for new users to use. So something like this:


[tab title="tab title"]Content of the first tab[/tab]

[tab title="second tab title"]Content of the second tab[/tab]


I understand why the function's notation is wrong but I figured I'd leave my best attempt.

share|improve this question
up vote 1 down vote accepted

Try This:

function defaulttab( $atts, $content = null ) {
    $GLOBALS['tab_count'] = 0;
    if( is_array( $GLOBALS['tabs'] ) ){
        $i = 1;
        foreach( $GLOBALS['tabs'] as $tab ){
            $tabs[] = '<li><a class="tab" href="#">'.$tab['title'].'</a></li>';
            $panes[] = '<div class="tab'.$i.'" class="tabcontent">' .$tab['content'].'</div>';
        $return = '<div class="tabcontainer"><ul class="selector">'.implode( "\n", $tabs ).'</ul>
            <div class="clear"></div>'.implode( "\n", $panes ).'</div>';
    return $return;

add_shortcode('tab', 'defaulttab');

function defaulttabs( $atts, $content = null ) {
    extract( shortcode_atts( array(
    'title' => '',
    'tab' => '1',
    ), $atts ) );

    $i = $GLOBALS['tab_count'];
    $GLOBALS['tabs'][$i] = array( 'title' => sprintf( $title, $GLOBALS['tab_count'] ), 'content' =>  $content );

add_shortcode('tabs', 'defaulttabs');
share|improve this answer
Thanks, it works (or rather will work with some slight modifications). I'm curious to understand how the function works, though (if you wouldn't mind explaining in brief detail). – pope Jan 31 '12 at 18:22
Paste that in the functions.php? – user25172 Dec 23 '12 at 20:48
@Helgi , yep in the functions.php would be fine. – Bainternet Dec 23 '12 at 21:01
Please igonre... spoke too soon – Sagive SEO Apr 24 '13 at 14:23

Your Answer


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.