Title: Adding PHP into a shortcode
Last modified: August 21, 2016

---

# Adding PHP into a shortcode

 *  [Phil](https://wordpress.org/support/users/owendevelopment/)
 * (@owendevelopment)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/adding-php-into-a-shortcode/)
 * Ok, I’m OK with PHP but not an expert. What’s the correct syntax here?
 * I’m trying to pull in an Advanced Custom Field data INSIDE some PHP, which is
   INSIDE a shortcode.
 * I have an ACF field called: the_sub_field(“google_doc_key”)
 * > <div><?php echo do_shortcode(“[gdoc key=’[https://docs.google.com/spreadsheets/d/”&#8216](https://docs.google.com/spreadsheets/d/”&#8216);.
   > the_sub_field(“google_doc_key”) .'”/edit’ gid=’0′]”); ?></div>
 * Somethings not right here… any help is appreciated.

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

 *  [TutsMix](https://wordpress.org/support/users/tutsmix/)
 * (@tutsmix)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/adding-php-into-a-shortcode/#post-4965554)
 * I’ve fixed your quotes:
 *     ```
       <div><?php echo do_shortcode('[gdoc key="https://docs.google.com/spreadsheets/d/'.the_sub_field('google_doc_key').'/edit" gid="0"]'); ?></div>
       ```
   
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/adding-php-into-a-shortcode/#post-4965556)
 * does the function `the_sub_field()` _return _or _echo _the result?
 * for the shortcode to work, you need to use a function which would **return **
   the result.
 * if you are not sure, please post in the plugin’s forum [http://wordpress.org/support/plugin/advanced-custom-fields](http://wordpress.org/support/plugin/advanced-custom-fields)

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

The topic ‘Adding PHP into a shortcode’ is closed to new replies.

## Tags

 * [ACF](https://wordpress.org/support/topic-tag/acf/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [11 years, 10 months ago](https://wordpress.org/support/topic/adding-php-into-a-shortcode/#post-4965556)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
