Skip to content

Instantly share code, notes, and snippets.

@danfisher85
Created June 15, 2014 17:00
Show Gist options
  • Save danfisher85/9ef8c8f02c43cf69a872 to your computer and use it in GitHub Desktop.
Save danfisher85/9ef8c8f02c43cf69a872 to your computer and use it in GitHub Desktop.
/*-----------------------------------------------------------------------------------*/
/* Tabs Shortcodes
/*-----------------------------------------------------------------------------------*/
$tabs_divs = '';
function tabs_group($atts, $content = null ) {
global $tabs_divs;
$tabs_divs = '';
$output = '<div class="tabs-wrapper"><ul class="nav nav-tabs">';
$output.= do_shortcode($content).'</ul>';
$output.= '<div class="tab-content">'.$tabs_divs.'</div>';
return $output;
}
add_shortcode('tab', 'tab');
function tab($atts, $content = null) {
global $tabs_divs;
extract(shortcode_atts(array(
'id' => '',
'title' => '',
'state' => ''
), $atts));
if(empty($id)) {
$id = 'side-tab'.rand(100,999);
}
$state_link = '';
if($state == 'open') {
$state = 'in active';
$state_link = 'active';
}
$output = '
<li class="'.$state_link.'">
<a href="#'.$id.'" data-toggle="tab">'.$title.'</a>
</li>
';
$tabs_divs.= '<div id="'.$id.'" class="tab-pane fade '.$state.'">'.$content.'</div>';
return $output;
}
add_shortcode('tabs', 'tabs_group');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment