Jump to content

variables in shortcode


Lassie

Recommended Posts

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?
 
Link to comment
https://forums.phpfreaks.com/topic/294653-variables-in-shortcode/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.