1

I want to put the variable in the shortcode, but it is not working. What i have done wrong.

<?php $calendar = getCalendarTag();?>
<?php echo do_shortcode( '[ai1ec tag_name=".$calendar."]"]' ) ?>    
1
  • 1
    Your shortcode is mssing quotes before the . and you also have an extra ]. It should be '[ai1ec tag_name="' . $calendar . '"]'; Commented Sep 3, 2015 at 16:57

3 Answers 3

5

Try changing your code to:

<?php echo do_shortcode('[ai1ec tag_name="' . $calendar . '"]'); ?>
1

Just use this line of code if you store shortcode in a variable:

<?php
 $contact_popup_form = '[contact-form-7 id="91" title="Contact form"]';
 echo do_shortcode($contact_popup_form);
?>
2
  • I don't think that's the problem, no: in your example the question would be how to set id or title from a PHP variable.
    – Rup
    Commented Nov 20, 2020 at 10:24
  • Then simply store values in php variables. e.g. $title = 'Contact Form'; $id=91; echo do_shortcode('[contact-form-7 id="'.$id.'" title="'.$title.'"]'); Commented Nov 21, 2020 at 11:54
0
  $val= $options['c_form'];
  echo do_shortcode("$val");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.