Title: Use shortcode inside custom widget
Last modified: August 21, 2016

---

# Use shortcode inside custom widget

 *  Resolved [Felix Arntz](https://wordpress.org/support/users/flixos90/)
 * (@flixos90)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/use-shortcode-inside-custom-widget/)
 * I’m using the shortcode inside a custom widget, however I get this PHP notice:
 * Trying to get property of non-object in …/plugins/comprehensive-google-map-plugin/
   shortcode.php on line 91
 * I know there’s a widget I should normally use, but I would like to display the
   map (by your plugin) inside a custom widget with some additional user information.
   The problem seems to be that your plugin tries to access the global $post variable–
   this is fine for the default usage, but it may throw the above notice when used
   in widgets.
 * The exact problem is the following: If you are on a site where no posts can be
   displayed (some kind of archive page without any posts attached), this notice
   is thrown since the global $post is not set. But even in the other cases, I suppose
   this shouldn’t be like that since the shortcode will access data from the last
   post rendered before the widget although it is completely independent from it.
 * Is there a way you can wrap this code with an if-clause to prevent this notice?
   Thank you!
 * [http://wordpress.org/plugins/comprehensive-google-map-plugin/](http://wordpress.org/plugins/comprehensive-google-map-plugin/)

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

 *  Plugin Contributor [alexanderzagniotov](https://wordpress.org/support/users/alexanderzagniotov/)
 * (@alexanderzagniotov)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/use-shortcode-inside-custom-widget/#post-4475844)
 * Thanks for that. Thats interesting because I dont get this notice on my sites.
   nonetheless I will add extra checking
 *  Plugin Contributor [alexanderzagniotov](https://wordpress.org/support/users/alexanderzagniotov/)
 * (@alexanderzagniotov)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/use-shortcode-inside-custom-widget/#post-4475863)
 * I want to email you the fixed plugin version, can you please email me at azagniotov[
   at] gmail?

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

The topic ‘Use shortcode inside custom widget’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/comprehensive-google-map-plugin_e2e4ef.
   svg)
 * [Comprehensive Google Map Plugin](https://wordpress.org/plugins/comprehensive-google-map-plugin/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/comprehensive-google-map-plugin/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/comprehensive-google-map-plugin/)
 * [Active Topics](https://wordpress.org/support/plugin/comprehensive-google-map-plugin/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/comprehensive-google-map-plugin/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/comprehensive-google-map-plugin/reviews/)

## Tags

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

 * 2 replies
 * 2 participants
 * Last reply from: [alexanderzagniotov](https://wordpress.org/support/users/alexanderzagniotov/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/use-shortcode-inside-custom-widget/#post-4475863)
 * Status: resolved