Title: do_shotcode issue using get_template_part
Last modified: August 21, 2016

---

# do_shotcode issue using get_template_part

 *  Resolved [elundin](https://wordpress.org/support/users/elundin/)
 * (@elundin)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/do_shotcode-issue-using-get_template_part/)
 * Hi!
 * First of all! Thanks for a fantastic plugin. I have used for a lot of static 
   content and worked brilliant.
 * This time I’m working on a site that dispplays cd-releases. Some of them will
   be available do everyone but some will be restricted to specific countries only.
 * I’m using the do_shortcode function as explained in the wordpress codex:
 * `echo do_shortcode('[iscorrect]'.$text_to_be_wrapped_in_shortcode.'[/iscorrect]');`
 * But instead of just showing text I want to use the same template part that I’m
   using for all the releases. Like this:
 *     ```
       if ( get_field('releaseCountry') == 'Japan' ) { $text_to_be_wrapped_in_shortcode = get_template_part( 'content', 'release' );
       echo do_shortcode('[CBC country="jp, ch" show="y"]'.$text_to_be_wrapped_in_shortcode.'[/CBC]');
       } else {
       get_template_part( 'content', 'release' );
       }
       ```
   
 * But when I’m using the get_templet_part in between the shortcode it shows the
   content anyway.
 * Am I doing anything wrong?
 * Cheers
 * //Emil
 * [http://wordpress.org/plugins/custom-content-by-country/](http://wordpress.org/plugins/custom-content-by-country/)

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

 *  Plugin Author [Paul](https://wordpress.org/support/users/paultgoodchild/)
 * (@paultgoodchild)
 * [12 years ago](https://wordpress.org/support/topic/do_shotcode-issue-using-get_template_part/#post-4004696)
 * Hi Emil,
 * I believe because this function, get_template_part(), will print out the contents
   of the template you’ve loaded whenever you call it… and you call it in both instances.
 * I don’t have an API access to getting the country code, but I’m planning to add
   that to a future release. That would make what you’re trying to achieve easier.
   Until then you could try:
 *     ```
       ob_start();
       get_template_part( 'content', 'release' );
       $text_to_be_wrapped_in_shortcode = ob_get_contents ();
       ob_end_clean();
   
       if ( get_field('releaseCountry') == 'Japan' ) {
       	echo do_shortcode('[CBC country="jp, ch" show="y"]'.$text_to_be_wrapped_in_shortcode.'[/CBC]');
       } else {
       	echo $text_to_be_wrapped_in_shortcode;
       }
       ```
   
 *  Thread Starter [elundin](https://wordpress.org/support/users/elundin/)
 * (@elundin)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/do_shotcode-issue-using-get_template_part/#post-4004699)
 * Thanks Paul, worked great!
 * Thank you for taking the time to help me and for a fantastic plugin. Keep up 
   the good work!
 * //Emil
 *  Plugin Author [Paul](https://wordpress.org/support/users/paultgoodchild/)
 * (@paultgoodchild)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/do_shotcode-issue-using-get_template_part/#post-4004701)
 * No problem at all… glad it worked for you! 🙂
 * Would you be interested in leaving a review for the plugin? 😉
 * Cheers,
    Paul.
 *  [tech17](https://wordpress.org/support/users/tech17/)
 * (@tech17)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/do_shotcode-issue-using-get_template_part/#post-4004702)
 * Hello Paul
 * Greetings For the day!!
 * I m using our plugin it is working very well in the pages, but i m facing an 
   issue to write a short code in the .php file
 * The thing is i want to show different contact number to there respective countries,
 * Can you please help me to write php short code for that.
 * You can see the contact number i want to change as per country
 * at the top [http://www.technoweber.com/](http://www.technoweber.com/)
 * Thank You Very much for such a wonderful plugin
 *  Plugin Author [Paul](https://wordpress.org/support/users/paultgoodchild/)
 * (@paultgoodchild)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/do_shotcode-issue-using-get_template_part/#post-4004705)
 * Hi,
 * Shortcodes cannot be used outside of posts, so the shortcodes for this plugin
   wont work.
 * However, if you have enabled the option in the plugin for developer mode, the
   plugin wont set cookies that reference the country code. It looks like on this
   link you sent that those cookies are not currently being set, so may be you have
   developer mode on.
 * What you can do is, check for those cookies when the pages load using PHP and
   change the phone number based on the country code. In this way you can display
   content you want to different countries. -but you’ll need the cookie data.
 * The cookie names for the country code is:
    cbc_country_code cbc_country_name
 * hope that helps.
    Paul.

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

The topic ‘do_shotcode issue using get_template_part’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-content-by-country.svg)
 * [Custom Content by Country (by Shield Security)](https://wordpress.org/plugins/custom-content-by-country/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-content-by-country/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-content-by-country/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-content-by-country/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-content-by-country/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-content-by-country/reviews/)

## Tags

 * [do_shortcode](https://wordpress.org/support/topic-tag/do_shortcode/)
 * [get_template_part](https://wordpress.org/support/topic-tag/get_template_part/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [shotcode](https://wordpress.org/support/topic-tag/shotcode/)

 * 5 replies
 * 3 participants
 * Last reply from: [Paul](https://wordpress.org/support/users/paultgoodchild/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/do_shotcode-issue-using-get_template_part/#post-4004705)
 * Status: resolved