简体   繁体   中英

Shortcode or PHP inside a shortcode in Wordpress

On a php page in wordpress, I have a shortcode for an accordion, that consists of the following, and works perfectly:

<?php echo do_shortcode('[su_accordion]
[su_spoiler title="Feature Locations" style="fancy"] CONTENT GOES HERE
[/su_spoiler]
[/su_accordion]'); ?>

Within the accordion, I want to display an interactive map, which can be displayed using either a shortcode, or PHP. Both options are:

[show-map id='1'], or
<?php build_i_world_map(1); ?>

When I insert either of these into the accordion shortcode, the map does not display. However, outside of the accordion, the second option above (with php) displays successfully.

What am I missing in terms of including this in the shortcode for the accordion?

In your example your outer section should be like

<?php echo do_shortcode('[su_accordion]
[su_spoiler title="Feature Locations" style="fancy"]'. build_i_world_map(1) .'
[/su_spoiler]
[/su_accordion]'); ?>

In wordpress you should call do_shortcode() for shortcode calls.

<?php echo do_shortcode("[show-map id='1']"); ?>

do_shortcode() reference

this is an effective way to include a concatenating inside a shortcode function

<?php echo do_shortcode('[download url='.$next_attachment_url.']'); ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM