I have a WordPress theme with a brief summary, with css styling, at the top of a post. This is wrapped in an if statement to only display if there is a summary.
Using the code below, the summary text displays, but the surrounding HTML markup is not included in the page source.
<?php if (get_smry_text($post)) { ?>
<div class="summaryWrap">
<div class="sumText">
<p><?php get_smry_text($post); ?></p>
</div>
</div>
<?php } ?>
Can anyone offer a suggestion as to why this might be?
It is possible that get_smry_text()
doesn't return any values.
Instead it echoes the content directly. If you are using this function you can do something like this:
<?php if ($smry = get_post_meta($post->ID, 'smry_text', true)) { ?>
<div class="summaryWrap">
<div class="sumText">
<p><? echo $smry; ?></p>
</div>
</div>
<?php } ?>
Try doing this:
<?php
$smry_text = get_smry_text($post);
if ($smry_text) {
$text = '<div class="summaryWrap">
<div class="sumText">
<p> ' . $smry_text . '</p>
</div>
</div>';
echo $text;
}
?>