Title: PHP question: echo inside echo to execute a shortcode?
Last modified: August 20, 2016

---

# PHP question: echo inside echo to execute a shortcode?

 *  [replicarlo](https://wordpress.org/support/users/replicarlo/)
 * (@replicarlo)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/php-question-echo-inside-echo-to-execute-a-shortcode/)
 * Hi guys
    I recognize that it is not very good with php, so I can not solve this
   problem: I’m using a plugin to manage some galleries on my website I would like
   to use the post_meta to change dinamically the value of a shortcode I’m not sure
   that I explained well 🙂 anyway this is the code:
 * <?php echo do_shortcode(‘[videogallery id=”
 *  <?php $video = get_post_meta($post->ID, ‘Video’, $single = true); ?>
    <?php 
   if($video !== ”) { ?> <?php echo $video; ?> <?php } else { echo ”; } ?>
 * “]’); ?>
 * this is the shortcode:
 * <?php echo do_shortcode(‘[videogallery id=”ID”]’); ?>
 * I’m trying to replace the “ID” with a post_meta but if I put this code:
    <?php
   $video = get_post_meta($post->ID, ‘Video’, $single = true); ?> <?php if($video!
   == ”) { ?> <?php echo $video; ?> <?php } else { echo ”; } ?> it seems to crash
   everything
 * Where I’m wrong?
    I appreciate any suggestion 🙂 Thank you

Viewing 1 replies (of 1 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/php-question-echo-inside-echo-to-execute-a-shortcode/#post-2292096)
 * you are using php tags in what should be string concatenation; try:
 *     ```
       <?php echo do_shortcode('[videogallery id="'.get_post_meta($post->ID, 'Video', true).'"]'); ?>
       ```
   
 * (untested)
 * possibly add a conditional statement to the code, to check if the custom field
   is filled in;
    example:
 *     ```
       <?php $video = get_post_meta($post->ID, 'Video', true); if( $video ) echo do_shortcode('[videogallery id="' . $video . '"]'); ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘PHP question: echo inside echo to execute a shortcode?’ is closed to 
new replies.

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 1 reply
 * 2 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/php-question-echo-inside-echo-to-execute-a-shortcode/#post-2292096)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
