Title: [Plugin: Shortcodes Ultimate] Using shortcode in theme
Last modified: August 20, 2016

---

# [Plugin: Shortcodes Ultimate] Using shortcode in theme

 *  Resolved [miruru](https://wordpress.org/support/users/miruru/)
 * (@miruru)
 * [15 years ago](https://wordpress.org/support/topic/plugin-shortcodes-ultimate-using-shortcode-in-theme/)
 * First of all, fantastic plugin, works like a charm.
 * Anyway, my question is, using the `do_shortcode()` function, how would I set 
   it up for the tabs? I’ve tried this but it seems to append the `[/gn_tab][/gn_tabs]`
   after the text of my content.
 * This is what I have:
 *     ```
       <?php echo do_shortcode( '[gn_tabs]' ) ?>
       <?php echo do_shortcode( '[gn_tab title="content title"]' ) ?>
       <?php echo do_shortcode( 'shortcode to my content' ) ?>
       <?php echo do_shortcode( '[/gn_tab]' ) ?>
       <?php echo do_shortcode( '[/gn_tabs]' ) ?>
       ```
   
 * I’ve tested using the other shortcodes and they work find, i.e. displaying the
   bloginfo.
 * Any help would be most appreciated. Once again thank you for a fantastic plugin!

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Thread Starter [miruru](https://wordpress.org/support/users/miruru/)
 * (@miruru)
 * [15 years ago](https://wordpress.org/support/topic/plugin-shortcodes-ultimate-using-shortcode-in-theme/#post-2113493)
 * After posting my query, I started playing around and have managed to work this
   out but only for a single tab. I entered the shortcodes for the tabs in one `
   do_shortcode`command rather than split them up:
 * `<?php echo do_shortcode( '[gn_tabs][gn_tab title="TEST"][SHORTCODE FOR CONTENT][/
   gn_tab][/gn_tabs]' ) ?>`
 * How would this work if I have multiple tabs? As it still only display one tab.
 *  Plugin Author [Vova](https://wordpress.org/support/users/gn_themes/)
 * (@gn_themes)
 * [15 years ago](https://wordpress.org/support/topic/plugin-shortcodes-ultimate-using-shortcode-in-theme/#post-2113630)
 * Try this:
 *     ```
       <?php
       $my_tabs = '
       [gn_tabs]
          [gn_tab title="TEST"] Some content [/gn_tab]
          [gn_tab title="TEST"] Some content [/gn_tab]
          [gn_tab title="TEST"] Some content [/gn_tab]
       [/gn_tabs]
       ';
       echo do_shortcode( $my_tabs );
       ?>
       ```
   
 *  Thread Starter [miruru](https://wordpress.org/support/users/miruru/)
 * (@miruru)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/plugin-shortcodes-ultimate-using-shortcode-in-theme/#post-2113706)
 * thank you. That worked perfectly!!!
 * Another quick question re the above code.
 * How would I use the IF / ELSE statement with the above code? The content is displayed
   in a custom field.
 * For example:
 * 1. Tab A and Tab B will always be displayed.
    2. If not empty, display Tab C,
   however do not display. 3. If not empty, display Tab D, however do not display.
 * Is this possible?
 * Thank you again for a great plugin!
 *  Plugin Author [Vova](https://wordpress.org/support/users/gn_themes/)
 * (@gn_themes)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/plugin-shortcodes-ultimate-using-shortcode-in-theme/#post-2113707)
 * You just need to create complete code in variable before do_shortcode execution.
   
   Example:
 *     ```
       $return = '[gn_tabs]';
       $return .= '[gn_tab title="..."] TAB A [/gn_tab]';
       $return .= '[gn_tab title="..."] TAB B [/gn_tab]';
   
       if ( !empty( $c ) ) {
          $return .= '[gn_tab title="..."] TAB C [/gn_tab]';
       }
   
       $return .= '[/gn_tabs]';
   
       // Now, variable has complete code, and we can execute it
   
       echo do_shortcode( $return );
       ```
   
 *  Thread Starter [miruru](https://wordpress.org/support/users/miruru/)
 * (@miruru)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/plugin-shortcodes-ultimate-using-shortcode-in-theme/#post-2113712)
 * Hu gn_themes, thank you for the speedy response.
 * I’ve tried the following:
 *     ```
       <?php
   
       $return .= '[gn_tabs style="2"]';
       $return .= '[gn_tab title="table"] [table] [/gn_tab]';
       $return .= '[gn_tab title="field1"] [field1] [/gn_tab]';
   
       if ( !empty( $c ) ) {
          $return .= '	[gn_tab title="field2"][field2"][/gn_tab]';
       }
   
       if ( !empty( $c ) ) {
          $return .= '	[gn_tab title="field3"][field3][/gn_tab]';
       }
   
       $return .= '[/gn_tabs]';
   
       // Now, variable has complete code, and we can execute it
       echo do_shortcode( $return );
       ?>
       ```
   
 * However this only displayed the first tab only. I’m not sure what i’m doing wrong.
   I’m not PHP efficient but I am learning. Any help would be most appreciated.
 *  Plugin Author [Vova](https://wordpress.org/support/users/gn_themes/)
 * (@gn_themes)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/plugin-shortcodes-ultimate-using-shortcode-in-theme/#post-2113713)
 * **wrong:** `$return .= '[gn_tabs style="2"]';` – stray dot
    **right:** `$return
   = '[gn_tabs style="2"]';`
 * **wrong:**
 *     ```
       if ( !empty( $c ) ) {
          $return .= '	[gn_tab title="field2"][field2"][/gn_tab]';
       }
       ```
   
 *  – stray quotes
    **right:**
 *     ```
       if ( !empty( $c ) ) {
          $return .= '	[gn_tab title="field2"][field2][/gn_tab]';
       }
       ```
   
 * And don’t forget to specify $c
 * Double check you code, before testing.
 *  Thread Starter [miruru](https://wordpress.org/support/users/miruru/)
 * (@miruru)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/plugin-shortcodes-ultimate-using-shortcode-in-theme/#post-2113714)
 * Thank you again for speedy response.
 * Also thank you for pointing out the stray . and quotes, they have been removed.
 * I have now managed to get this working with the following:
 *     ```
       <?php
       $return = '[gn_tabs style="2"]';
       $return .= '[gn_tab title="table"] [table] [/gn_tab]';
   
       if ( fs_get_meta('field1') !== ''  ) {
          $return .= ' [gn_tab title="field1"][field1][/gn_tab] ';
       }
       if ( fs_get_meta('field2') !== ''  ) {
          $return .= '	[gn_tab title="field2"][field2][/gn_tab]';
       }
       if ( fs_get_meta('field3') !== ''  ) {
          $return .= '	[gn_tab title="field3"][field3][/gn_tab]';
       }
   
       $return .= '[/gn_tabs]';
   
       // Now, variable has complete code, and we can execute it
       echo do_shortcode( $return );
       ?>
       ```
   
 * Thank you for this fantastic plugin.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘[Plugin: Shortcodes Ultimate] Using shortcode in theme’ is closed to 
new replies.

 * ![](https://ps.w.org/shortcodes-ultimate/assets/icon-256x256.gif?rev=2547563)
 * [Shortcodes Ultimate - Content Elements](https://wordpress.org/plugins/shortcodes-ultimate/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/shortcodes-ultimate/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/shortcodes-ultimate/)
 * [Active Topics](https://wordpress.org/support/plugin/shortcodes-ultimate/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/shortcodes-ultimate/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/shortcodes-ultimate/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [miruru](https://wordpress.org/support/users/miruru/)
 * Last activity: [14 years, 12 months ago](https://wordpress.org/support/topic/plugin-shortcodes-ultimate-using-shortcode-in-theme/#post-2113714)
 * Status: resolved