Title: PHP Widget and do_shortcode
Last modified: August 20, 2016

---

# PHP Widget and do_shortcode

 *  [bst](https://wordpress.org/support/users/bst/)
 * (@bst)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-widget-and-do_shortcode/)
 * I am trying to use custom fields to pull through the location from a post/page
   and use as a widget in the sidebar
 * I have found the following thread where someone has got it working but the code
   doesnt appear to work for me:
 *     ```
       <?php echo do_shortcode('[forecast location="' . $city . ' , ' . $state . '" caption="' . $city . ' , ' . $state . '" numdays="3" iconset="Cartoon" class="css_table_class" cache="true"]'); ?>
       ```
   
 * This is what I have and it works:
 *     ```
       <?php
       $city = get_the_title();
       $country = UK;
       echo do_shortcode ('[forecast location= "London, ' . $country . '" caption=" ' . $city. ', ' . $country . '" numdays="2" iconset="Cartoon" class="css_table_class" cache="true"]'
       );
       ?>
       ```
   
 * HOWEVER, as soon as I try to pull in the $city and replace the above code for
   the forecast location= with
 *     ```
       "' . $city . ', ' . $country . '" it stops working
       ```
   
 * Anyone have any ideas please?
 * [http://wordpress.org/extend/plugins/wunderground/](http://wordpress.org/extend/plugins/wunderground/)

The topic ‘PHP Widget and do_shortcode’ is closed to new replies.

 * ![](https://ps.w.org/wunderground/assets/icon-256x256.jpg?rev=1000977)
 * [Weather Underground](https://wordpress.org/plugins/wunderground/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wunderground/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wunderground/)
 * [Active Topics](https://wordpress.org/support/plugin/wunderground/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wunderground/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wunderground/reviews/)

## Tags

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

 * 0 replies
 * 1 participant
 * Last reply from: [bst](https://wordpress.org/support/users/bst/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/php-widget-and-do_shortcode/)
 * Status: not resolved