Title: Adding php within shortcode?
Last modified: October 11, 2017

---

# Adding php within shortcode?

 *  [aaronrobb](https://wordpress.org/support/users/aaronrobb/)
 * (@aaronrobb)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/adding-php-within-shortcode/)
 * I’m having an issue with the shortcode.
    Here’s what i have in my theme file:
 *     ```
       <?php echo do_shortcode('[geot exclude_country="CA"]' . get_field("details") . '[/geot]'); ?>
       <?php echo do_shortcode('[geot country="CA"]' . get_field("details_cad") . '[/geot]'); ?>
       ```
   
 * The issue is that the [/geot] shows up in the front end. I’m assuming the get_field
   tag is causing the shortcode to end before the actual [/geot]. The issue is I
   have the two shortcodes and i’m not sure what the best method for doing this 
   is….
 * Has anyone else had this issue?

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

 *  Plugin Author [Damian](https://wordpress.org/support/users/timersys/)
 * (@timersys)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/adding-php-within-shortcode/#post-9578636)
 * if you remove the get_field the shortcode works fine? For example using any other
   string?
 * What about doing :
 *     ```
       $details = get_field('details');
       <?php echo do_shortcode('[geot exclude_country="CA"]' . $details . '[/geot]'); ?>
       ```
   
 *  Thread Starter [aaronrobb](https://wordpress.org/support/users/aaronrobb/)
 * (@aaronrobb)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/adding-php-within-shortcode/#post-9580536)
 * Damian
 * Yes the shortcode works great if its just pure content in it.
 * The issue is that i’m trying to pull in a Shopify “Buy Now” button code in that
   field and part of that is javascript. I’m assuming that is breaking the shortcode.
   The button code on its own works fine, and with your plugin’s shortcode working
   good, I’m assuming that it just doesn’t like the script in it.
 * I’ve tried the setup you suggest there ($details = get_field) and still breaks.

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

The topic ‘Adding php within shortcode?’ is closed to new replies.

 * ![](https://ps.w.org/geotargeting/assets/icon-256x256.png?rev=1829366)
 * [GeoTargeting Lite - WordPress Geolocation](https://wordpress.org/plugins/geotargeting/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/geotargeting/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/geotargeting/)
 * [Active Topics](https://wordpress.org/support/plugin/geotargeting/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/geotargeting/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/geotargeting/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [aaronrobb](https://wordpress.org/support/users/aaronrobb/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/adding-php-within-shortcode/#post-9580536)
 * Status: not resolved