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
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.

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.