I have a geolocation shortcode which i am adding in the post editor to display different information based on user’s location, works perfectly by having it in the post page content.
How can i execute this shortcode [geolocation][/geolocation] inside a PHP file of my theme? i am using a free to modify WordPress theme and i want to add a new <span>[geolocation][/geolocation]Information text content</span> but inside the theme’s .php file, how can i do that? if i add straight the <span>[geolocation][/geolocation]Information text content</span> it will show the shortcode as text, it won’t execute, please help, thanks in advance.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Found it: <?php echo do_shortcode( '[your shortcode goes here]' ); ?>
Method 2
You can Execute the shortcode in php like the following
echo do_shortcode("[geolocation]");
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0