Embedded Shortcodes – more than one causes error
-
Seems like if I embed more than one shortcode inside [thermometer ], the second shortcode doesn’t work. I want my thermometer to be dynamic, so I fetch numbers as strings from outside my website using a shortcode I created called [fetch_url url=”https://myurl]
I’ve created a test page for you to look at. The first thermometer uses my shortcode to fetch the thermometer value and hard codes the target(s) as: 0;3.05;5.97;8 , baseline of 0, low value of 3.05, high value of 5.97 and maximum of 8. No problem using my shortcode to fetch the “raised” amount. Shortcode looks like this:
[thermometer raised=’fetch_url url=”https://wells.orientassociation.org/height.html”‘ target=0;3.05;5.97;8]
The second thermometer on the page uses this shortcode:
[thermometer raised=’fetch_url url=”https://wells.orientassociation.org/height.html”‘ target=’fetch_url url=”https://wells.orientassociation.org/targets.html”‘%5D
targets.html returns the same values as the hardcoded version in the first thermometer.
Look at the bottom of the page where [fetch_url url=”https://wells.orientassociation.org/targets.html%5D is used successfully.
Bottom of the page looks like this:
The targets are: 0;3.05;5.97;8
On 2025-09-10 10:48 the groundwater height was: 3.05 ft.
For the past 15 months low water was: 3.05 ft.
For the past 15 months high water was: 5.97 ft.
Shortcodes for the bottom of the page looks like this:
The targets are: [fetch_url url=”https://wells.orientassociation.org/targets.html”%5D
On [fetch_url url=”https://wells.orientassociation.org/date.html”%5D the groundwater height was: [fetch_url url=”https://wells.orientassociation.org/height.html”%5D ft.
For the past 15 months low water was: [fetch_url url=”https://wells.orientassociation.org/low.html”%5D ft.
For the past 15 months high water was: [fetch_url url=”https://wells.orientassociation.org/high.html”%5D ft.
-
This topic was modified 6 months, 1 week ago by
Nductiv.
The page I need help with: [log in to see the link]
-
This topic was modified 6 months, 1 week ago by
-
The target parameter wasn’t set up to handle shortcodes as I assumed this would probably remain constant in most use cases. But it’s easy enough to do.
In therm_shortcode.php, search for the target value section (around line 100) and this ‘if loop’ in the last else statement.
// if shortcode present
if (!is_numeric(str_replace(",", ".", $atts['target'])) && (strpos($atts['target'], ';') === false) && !is_numeric(str_replace(',','',$atts['target']))) {
$shortcode = "[".strval($atts['target'])."]";
$atts['target'] = do_shortcode( $shortcode);
}Use the raised value section underneath as a guide. The two different shortcodes should then be parsed ok.
I can include this in the next plugin update, as it could be useful for others.
I’ll hang loose till the next plugin update.
BTW – you are totally awesome for responding so quickly and thoroughly! Just sent you a donation.That’s awesome, thank you!
The topic ‘Embedded Shortcodes – more than one causes error’ is closed to new replies.