Title: Shortcode in php template
Last modified: March 25, 2022

---

# Shortcode in php template

 *  Resolved [mattov](https://wordpress.org/support/users/mattov/)
 * (@mattov)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/shortcode-in-php-template/)
 * Hi
 * Great plugin.
 * I have a site with multiple walking routes. I have created a custom post type
   for the routes. I am trying to add a map to each route, each with a different.
   gpx file. I have created a custom field on the route post type for the url of
   the .gpx file.
 * I have tried many ways to replace the url in the shortcode below with the url
   in the custom field (the_field, using a variable, putting the entire shortcode
   in a custom field, etc.) but I cannot get it to work.
 * echo do_shortcode(‘[osmap gpx=”[https://site/file.gpx”%5D&#8217](https://site/file.gpx”%5D&#8217););
 * What I want to do is add the .gpx file to the custom field of each route and 
   then use the template and shortcode to display the right map on the right page.
 * My php is limited, so any help would be greatly appreciated.
 * Many thanks

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

 *  Plugin Author [skirridsystems](https://wordpress.org/support/users/skirridsystems/)
 * (@skirridsystems)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/shortcode-in-php-template/#post-15494991)
 * This looks like a PHP/WordPress problem rather than a plugin problem. You’ll 
   need to give a bit more information too; ‘using a variable’ doesn’t tell me much.
   What is the exact code you’ve tried?
 * First things first: try
    `echo do_shortcode('[osmap]');`
 * That should show the default map centred on OS HQ.
 * Try dropping the do_shortcode() and just echo the bare shortcode. That way you’ll
   get to see what do_shortcode is seeing in each of your methods. e.g.
    `echo '[
   osmap gpxfile="https://site/file.gpx"]';`
 * Don’t forget that variables are expanded in double-quoted strings but not in 
   single-quoted strings.
    `echo do_shortcode("[osmap gpxfile='$filepath']");` will
   give a very different result from `echo do_shortcode('[osmap gpxfile="$filepath"]');`
 * Simon
 *  Thread Starter [mattov](https://wordpress.org/support/users/mattov/)
 * (@mattov)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/shortcode-in-php-template/#post-15502146)
 * Hi Simon
 * Yes, it was very much a php problem, the plugin works fine.
 * Thank you for your response, that helped. I’ve had a play and found that the 
   following code works, where ‘os_map_embed’ is my custom field for the gpx url:
 *  `echo do_shortcode('[osmap gpx='.'"'.get_field('os_map_embed').'"'.']');`
 * I had my .s, ‘s and “s in all the wrong places!
 * Thanks

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

The topic ‘Shortcode in php template’ is closed to new replies.

 * ![](https://ps.w.org/os-datahub-maps/assets/icon-256x256.jpg?rev=2376803)
 * [OS DataHub Maps](https://wordpress.org/plugins/os-datahub-maps/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/os-datahub-maps/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/os-datahub-maps/)
 * [Active Topics](https://wordpress.org/support/plugin/os-datahub-maps/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/os-datahub-maps/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/os-datahub-maps/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [mattov](https://wordpress.org/support/users/mattov/)
 * Last activity: [4 years, 2 months ago](https://wordpress.org/support/topic/shortcode-in-php-template/#post-15502146)
 * Status: resolved