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!
https://www.ads-software.com/plugins/comprehensive-google-map-plugin/
- The topic ‘Use shortcode inside custom widget’ is closed to new replies.