Lassie Posted February 16, 2015 Share Posted February 16, 2015 I am using a wordpress gallery shortcode that will display images when passed the id as so [gallery include = "499, 496] , which will display the attached images from two ids. I need the ids to be passed as variables, for example $image1= '499'; and $image2='496'; I have the following concatenation which works with one value but not two. $image1="499"; $image2="496"; $images= $image1.$image2; echo do_shortcode('[gallery include =' . $image1 .']'); //works for image1 echo do_shortcode('[gallery include =' . $image1 .'' . $image2 .']'); // only shows first image Should I expect this to work? Quote Link to comment https://forums.phpfreaks.com/topic/294653-variables-in-shortcode/ Share on other sites More sharing options...
maxxd Posted February 16, 2015 Share Posted February 16, 2015 You're not separating the numbers. If you look at your example, you've got [gallery include="499,496"] but your built string is reading [gallery include="499496"] Try changing the do_shortcode() call to echo do_shortcode("[gallery include='{$image1},{$image2}']"); Note the comma separator between the variables. 1 Quote Link to comment https://forums.phpfreaks.com/topic/294653-variables-in-shortcode/#findComment-1505830 Share on other sites More sharing options...
Lassie Posted February 16, 2015 Author Share Posted February 16, 2015 Thanks I will try that. Quote Link to comment https://forums.phpfreaks.com/topic/294653-variables-in-shortcode/#findComment-1505833 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.