• Hello everybody,
    Here’s a silly question. And I’m sure I should know how to do it but I think I don’t have all my neurones at the same place today.
    So I have a php variable containing the shortcode of a cf7 form :
    $formPerso = '[contact-form-7 id="1538" title="Form1"]';
    (this example is fictional as I retrieve a custom field value in place of the shortcode. This means $formPerso value should be the full shortcode)
    I would like to use this variable in a ‘do_shortcode’.
    like this :
    echo do_shortcode($formPerso);

    obviously it gives me an error. How should I do to make it works?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Works for me. Perhaps the issue is with however you’re retrieving the shortcode to put it in a variable?

    If you’re using get_post_meta, make sure the 3rd argument is true, so that you get a string.

    Thread Starter trouille2

    (@trouille2)

    Hmmm…
    What I have in result is this : [contact-form-7 404 “Not Found”]
    the third argument is true…But to be honest, I use advanced custom field to generate the custom field. I’ve checked on ACF website and by default, the get_post_meta is set to true.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘do_shortcode with variable’ is closed to new replies.