-1

Hey I'm currently using wordpress to create a website and as I'm new to PHP I'm having some trouble adding an integer into a shortcode command. This is the code I'm currently using:

<?php $store_id  = 1;
echo do_shortcode('[dokan-stores store_id= "%1$s"]',"$store_id"); ?>

When I use this code

<? echo do_shortcode('[dokan-stores store_id= "1"]'); ?>

Everything works fine however I can't get it to work with an embedded variable, I've tried lots of methods but none are working.

Thanks,

Charlie

charlietlamb
  • 79
  • 1
  • 1
  • 9
  • 2
    `%1$s` is printf syntax, but you are not in a printf context here. Either wrap a call of `sprintf` into your `do_shortcode` call ... or just use simple string concatenation at this point. – CBroe May 31 '23 at 11:23

1 Answers1

0

You should use it like this

<?php
$store_id = 1;
$shortcode = sprintf('[dokan-stores store_id="%d"]', $store_id);
echo do_shortcode($shortcode);
?>
Vikas Rana
  • 49
  • 7