Title: Adding more complex shortcode to PHP code
Last modified: August 29, 2017

---

# Adding more complex shortcode to PHP code

 *  Resolved [searay](https://wordpress.org/support/users/searay/)
 * (@searay)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/adding-more-complex-shortcode-to-php-code/)
 * Hello,
 * I have a shortcode which I want to use in the template, but the problem is I 
   want to also include PHP code in it. Here is an example of what I am after.
 * `<?php echo do_shortcode('[su_list icon="icon: angle-double-right" icon_color
   ="#800000" ]<a href="#Savings">Savings in <?php echo $city; ?></a>[/su_list]');?
   >`
 * I want to output the city on the frontend i.e. “Savings in New York” but it looks
   like the php code is omited and I got only “Savings in” instead, is there any
   way to force it to work that way? The code works outside of shortcode without
   any problems.

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/adding-more-complex-shortcode-to-php-code/#post-9452291)
 * try and use string concatenation:
 * `<?php echo do_shortcode('[su_list icon="icon: angle-double-right" icon_color
   ="#800000" ]<a href="#Savings">Savings in ' . $city . '</a>[/su_list]'); ?>`
 * is `$city` definded somewhere before your code?
 *  Thread Starter [searay](https://wordpress.org/support/users/searay/)
 * (@searay)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/adding-more-complex-shortcode-to-php-code/#post-9452327)
 * Yes, it is and your solution works magic! Thanks! Problem solved!

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

The topic ‘Adding more complex shortcode to PHP code’ is closed to new replies.

## Tags

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

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 2 participants
 * Last reply from: [searay](https://wordpress.org/support/users/searay/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/adding-more-complex-shortcode-to-php-code/#post-9452327)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
