Unexpected $code (T_VARIABLE) error in php

I have a code

$code = get_field('x_download');

where $code will get a number value say 192

Read More

now when i do

echo do_shortcode('email-download download_id="$code" contact_form_id="2"]');

i’m unable to get value of $code i.e 192 in download_id
I’m sure something is wrong with my syntax

Related posts

2 comments

  1. Replace your line with this:

     do_shortcode("email-download download_id='$code' contact_form_id='2']");
    

    Single quotes will not replace your PHP variable with value, instead it prints the variable as it is. Double quotes will do the replacement.

  2. You can do it as shown below

    <?php  $code = get_field('ebooks_download');                            
    
    echo do_shortcode('[email-download download_id='.get_field('ebooks_download').' contact_form_id="1420"]'); ?>
    

Comments are closed.