0
votes

I am currently using a theme which comes with a set of shortcodes.

I would like to include a shortcode inside a shortcode. One comes from a social share plug-in called ShareThis whilst the other is part of the theme.

However, when I nest the shortcode, it just does not work.

I have also tried this plug-in but it is not working either. The shortcode I am trying to add is below. [st_buttons] Is the shortcode i am trying to nest.

[flip_image animate='flip' delay='' flip_on_appear=''     front_image_link='' back_image_link='' background_color='#f2f2f2' back_text='[st_buttons]' link='' target='']

Update Shortcode function

if (!function_exists('flip_image')) {
function flip_image($atts, $content = null) {
extract(shortcode_atts(array("animate" => "", "flip_on_appear" => "",     "delay" =>"", "front_image_link" => "", "back_image_link" => "", "background_color" => "", "back_text" => "", "link" => "", "target" => ""), $atts));
$html = "";  

if($front_image_link != "" && $back_image_link != ""){
    $html .=  '<div class="flip_image_holder '.$animate.' '.$flip_on_appear.'" data-delay="'.$delay.'"><a href="'.$link.'" target="'.$target.'"><div class="flip_image front"><img src="'.$front_image_link.'" alt="'.getImageAltFromURL($front_image_link).'" /></div><div class="flip_image back"><div class="flip_image_text"><div class="flip_image_text_inner"><img src="'.$back_image_link.'" alt="'.getImageAltFromURL($back_image_link).'" /></div></div></div></a></div>';
} else {
    $html .=  '<div class="flip_image_holder '.$animate.' '.$flip_on_appear.'" data-delay="'.$delay.'"><a href="'.$link.'" target="'.$target.'"><div class="flip_image front"><img src="'.$front_image_link.'" alt="'.getImageAltFromURL($front_image_link).'" /></div><div class="flip_image back" style="background-color: '.$background_color.';"><div class="flip_image_text"><div class="flip_image_text_inner"><h4>'.$back_text.'</h4></div></div></div></a></div>';
}

return $html;
 }
 }
 add_shortcode('flip_image', 'flip_image');
1
Can I just confirm that your output ends up with back_text="[st_buttons]" with the shortcode just staying as it is? - Simon Pollard
yes that is correct the main shortcode is the [flip_image] and [st_buttons] is the shortcode. However when i insert it as above it breaks and just shows a '] on the page. - user1673498
You will need to edit the first shortcode function to make sure it calls do_shortcode() with the content it gets passed through developer.wordpress.org/reference/functions/do_shortcode otherwise it just outputs it as text and you end up with [] like you said - Simon Pollard
Hi, thanks for the information, i have now updated the question with the first shortcode code like you asked, any ideas? - user1673498

1 Answers

0
votes

If you are able to update that shortcode you need to make a change where it refers to back_text and add in the do_shortcode() function:

<h4>'.do_shortcode($back_text).'</h4>

That should then run the second [st_buttons] shortcode function that you need.