• Resolved mattov

    (@mattov)


    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’);

    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

    (@skirridsystems)

    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

    (@mattov)

    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.