admin管理员组

文章数量:1312690

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.

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.

Share Improve this question edited Dec 31, 2020 at 21:29 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Dec 31, 2020 at 14:30 JimmyJimmy 131 silver badge5 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

Found it: <?php echo do_shortcode( '[your shortcode goes here]' ); ?>

You can Execute the shortcode in php like the following

echo do_shortcode("[geolocation]");

本文标签: Execute shortcodes in PHP