Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP using a variable inside do_shortcode() - Wordpress Page Template

The format for the shortcode that I wish to do is: [product id="id#"] The format for do_shortcode is: do_shortcode('[shortcode');

My question is how can I insert a PHP variable as the id#?

I have a variable $itemid that I would like to use like this:

echo do_shortcode('[product id="$itemid"])

But I cannot for the life of me get it to work. Any suggestions would be greatly appreciated.

like image 319
Lucas Mercer Avatar asked Dec 02 '22 14:12

Lucas Mercer


1 Answers

This is an issue of single quotes vs double quotes,

see What is the difference between single-quoted and double-quoted strings in PHP?

this fix should work:

echo do_shortcode("[product id=\"$itemid\"]")
like image 139
Uri Goren Avatar answered Dec 06 '22 03:12

Uri Goren