Nesting Echo's or Output Variable Differently?

Nesting Echo's or Output Variable Differently?

I am trying to check to make sure a custom-field is not blank before echoing the custom-field.

This is what I have

<?php 
  $key = 'one_line_summary'; 
  $themeta = get_post_meta($post->ID, $key, TRUE); 
  if($themeta != '') {
    echo '<blockquote><?php echo get_post_meta($post->ID, one_line_summary, true); ?></blockquote>';
  }
?>

But it out puts the "get_post_meta($post->ID, one_line_summary, true);" literally rather than the contents of the variable one_line_summary.

I am a beginner but I feel like I need to either use nested echo's somehow or change the second echo all together?

Thanks in advance.

1 Answer

You have nested <?php ?> inside an existing set of PHP tags, which is not allowed. Remove those, and concatenate in the function call to get_post_meta(). What happened here is that the inner <?php ?> tags were output as strings to the browser, but not rendered onscreen (since the browser treated them as unknown HTML tags).

echo '<blockquote>' .  get_post_meta($post->ID, one_line_summary, true) . '</blockquote>';

As a note, these kinds of issues are considerably easier to spot with proper code indentation as was done when your post was edited above.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.