Title: Tab shortcode with custom fields
Last modified: August 20, 2016

---

# Tab shortcode with custom fields

 *  Resolved [Corbula](https://wordpress.org/support/users/corbula/)
 * (@corbula)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/)
 * I’ve got a template file which uses custom field and i want to use shortcodes
   in the file as well.
 * The shortcode makes the content appear in tabs on the page.
 * I’ve had a go but i’m not a php developer. It comes up with an error saying Unexpected
   T_STRING. The error comes on the first do_shortcode line.
 * Here’s the code:
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       			<h1><?php the_title(); ?></h1>
                   	<?php do_shortcode("[tab name='Overview']<div id="product-image"><?php the_post_thumbnail(); ?></div>
       				<?php the_field('overview'); ?>[/tab]");
                       do_shortcode("[tab name='Features & Benefits']<?php the_field('features_&_benefits'); ?>[/tab];");
                       do_shortcode("[tab name='Options & Accessories']<?php the_field('options_&_accessories'); ?>[/tab];");
                       do_shortcode("[tab name='Downloads']<a href="<?php the_field('downloads'); ?>">Download PDF</a>[/tab];");
                       do_shortcode("[tab name='Supplies']<?php the_field('supplies'); ?>[/tab];");
                       echo do_shortcode("[end_tabset]");?>
       ```
   
 * Anybody know how to get this to work?
 * Thanks

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

 *  [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * (@rvoodoo)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309081)
 *     ```
       <?php do_shortcode("[tab name='Overview']<div id="product-image"><?php the_post_thumbnail(); ?></div>
       ```
   
 * Well, looking at that code…
 *     ```
       <?php do_shortcode("[
       ```
   
 * has an opening php tag, bracket, and an opening double quote, there are no closing
   php tag, bracket, or double quote
 *  Thread Starter [Corbula](https://wordpress.org/support/users/corbula/)
 * (@corbula)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309138)
 * That’s because the line below is supposed to be part of the same tab.
 * Does it have to be on the same line?
 *  [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * (@rvoodoo)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309146)
 * That won’t work because here
 *     ```
       <?php do_shortcode("[tab name='Overview']<div id="product-image"><?php
       ```
   
 * you nest php
 * You have an opening php tag, and then another opening php tag … you can’t open
   a php command if it’s already open.
 *  Thread Starter [Corbula](https://wordpress.org/support/users/corbula/)
 * (@corbula)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309156)
 * The reason for that is to encapsulate the fields in the shortcode. Notice the[/
   tab].
 * I’ve tried this, it loads the page but does use tabs like i’m trying to get the
   shortcodes to do.
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 *  Thread Starter [Corbula](https://wordpress.org/support/users/corbula/)
 * (@corbula)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309164)
 * [http://pastebin.com/WvPfHRw9](http://pastebin.com/WvPfHRw9)
 *  [Peter Baylies](https://wordpress.org/support/users/pbaylies/)
 * (@pbaylies)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309185)
 * Quotes in PHP don’t work the way you want them to; I would suggest using PHP 
   output buffering for this instead:
 * [http://pastebin.com/PrT5hVS7](http://pastebin.com/PrT5hVS7)
 *  Thread Starter [Corbula](https://wordpress.org/support/users/corbula/)
 * (@corbula)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309207)
 * Thanks for that however, it’s not working and i’m not familiar with the syntax
   of output buffering. When using output buffering do you not need do_shortcode?
 * It’s just displaying the page but putting ob_start() and [tab name] and things
   in the actual page content.
 * Is it missing anything from the code?
 *  [Peter Baylies](https://wordpress.org/support/users/pbaylies/)
 * (@pbaylies)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309253)
 * Yes, for some reason a couple of PHP tags didn’t show up; see if this works better:
 * [http://pastebin.com/6unjXyZu](http://pastebin.com/6unjXyZu)
 * Also note that do_shortcode() is still there at the bottom, the only difference
   is that we’re putting that section of the page into the $output_buffer variable,
   using PHP’s output buffering. This avoids the quoting issues you were running
   into before.
 *  Thread Starter [Corbula](https://wordpress.org/support/users/corbula/)
 * (@corbula)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309257)
 * Thanks but there’s still something wrong.
 * The page loads but it’s still not loading in tabs and it’s printing all of the[
   tab name=””] and [/tabs].
 * Should there not be some php around them or something so it doesn’t just print
   them on the page?
 *  [Peter Baylies](https://wordpress.org/support/users/pbaylies/)
 * (@pbaylies)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309258)
 * If you’re using that code in your template, then that sounds like an issue with
   your [tab] shortcode (it is [tab] and not [tabs]?). Test those shortcodes on 
   a page and verify that they work on the site. The PHP that executes them would
   be the do_shortcode() at the bottom. Good luck!
 *  Thread Starter [Corbula](https://wordpress.org/support/users/corbula/)
 * (@corbula)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309276)
 * Yes i’m trying to use it in a template file so it does it automatically and so
   you don’t have to use them every time you post something.
 * It works in a post but the post type i’m using has multiple editors. If i try
   and use it across multiple editors it doesn’t work. I’m assuming it’s because
   i’m also using the featured image in the template and because you can’t add a
   shortcode to that it fails the whole page.
 * That’s why i want to use it in the template so it can do all of the content and
   do it automatically.
 *  Thread Starter [Corbula](https://wordpress.org/support/users/corbula/)
 * (@corbula)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309337)
 * I’ve not been able to get your code to work. I’ve tried numerous different tweaks
   with your code and i’ve not got it to work.
 * I’ve also tried the following, which may be wrong but i thought the . in the 
   code might work instead of using multiple <?php tags.
 * [http://pastebin.com/qduevTMQ](http://pastebin.com/qduevTMQ)
 * The plugin i’m using for the tabs is this.
 * [http://wordpress.org/extend/plugins/put/](http://wordpress.org/extend/plugins/put/)
 * I’m stumped with what else i can try.
 *  Thread Starter [Corbula](https://wordpress.org/support/users/corbula/)
 * (@corbula)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309369)
 * Just to let you know i’ve managed to do this using a different plugin.
 * [http://wordpress.org/extend/plugins/wp-ui/](http://wordpress.org/extend/plugins/wp-ui/)
 *  [Peter Baylies](https://wordpress.org/support/users/pbaylies/)
 * (@pbaylies)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309371)
 * Great, glad to hear it; sorry the other one didn’t work out for you.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309438)
 * Sorry i wasn’t here to help you along sooner, but i can see a couple of issues
   in the way you were approaching your custom code.
 * Firstly, the tab names/titles do not support HTML(that info does exist in the
   plugin’s FAQ page), those names have to be sanitized seperately and i considered
   it unsafe to let users post HTML inside there and running the content through
   kses would have only slowed down the plugin’s operation. It’s certainly something
   i could look at again, but i felt it was the right choice initially when i made
   the call(no reason i can’t re-evaluate that decision though).
 * Secondly, `the_field` is not a WP function, so i assume specific to your theme(
   or a plugin), but in any case it may not give a `return` value, which i think
   you’ll need if using it inside `do_shortcode`, same applies to `the_post_thumbnail`
   which would be need to be replaced with `get_the_post_thumbnail` (for a return
   value vs a printed one).
 * In any case, i’m glad to hear you were able to archieve what you wanted, and 
   sorry i wasn’t available to help sooner, best of luck with your WordPress site.

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

The topic ‘Tab shortcode with custom fields’ is closed to new replies.

## Tags

 * [Post UI Tabs](https://wordpress.org/support/topic-tag/post-ui-tabs/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 15 replies
 * 4 participants
 * Last reply from: [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * Last activity: [14 years, 7 months ago](https://wordpress.org/support/topic/tab-shortcode-with-custom-fields/#post-2309438)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
