How to wrap div in php code?

Make a website on WordPress. Needed to create arbitrary extra field for articles (author name, by default this field is not present). After creating the file put in this code:
<div class="creator">
 <?php if( is_single() ) { //print only if the page record
 echo get_post_meta($post--->ID, 'creator', true); // actually, the conclusion
}
?>
</div>

Where 'creator' is the name of the custom field. A div class with the same name I created in order to give the formatting.
The code works, but the fact is that not all articles listed authors, and if the author is not present, then the div just sits here, empty space above the title appears that ugly.
Maybe it's better to wrap the div in the php code to the div took place only when the extra field is not empty? Something like:
<?php if(isset($row)) { //check availability
 echo 
 '<div class="creator"-->
 <?php if( is_single() ) { //print only if the page record
 echo get_post_meta($post--->ID, 'creator', true); // actually, the conclusion
}
?>
'
}
 ?>

But it doesn't work, you can see something very cumbersome and contradictory built. How can I do this?
June 14th 19 at 20:37
3 answers
June 14th 19 at 20:39
<?php if(isset($row) && is_single()) { ?> // Unclear what is isset($row), perhaps here it is necessary to do check for fields creator? if(get_post_meta($post->ID, 'creator', true))
 <div class="creator">
 <?php echo get_post_meta($post--->ID, 'creator', true);?>
</div>
<?php }?>


Is the default VP function for information about the author
https://developer.wordpress.org/reference/function...
About "defaulted function trip for more information about the author" probably refers to the author and the user who posted the entry?
And I need for when the user publishes the story, for example, Chekhov. Below the title you can write "Chekhov" - nikita.Stracke commented on June 14th 19 at 20:42
in this case, all right, you need an arbitrary field. - anika_Da commented on June 14th 19 at 20:45
June 14th 19 at 20:41
Just wrap the whole code in PHP and HTML and left, without any echo. In your case:
<?php if(isset($row)) { ?>
 <div class="creator">
 <?php if( is_single() ) { 
 echo get_post_meta($post--->ID, 'creator', true);
}
?>
</div>
<?php } ?>
June 14th 19 at 20:43
Not working. Just nothing appears.
var_dump($row);
And see that check. - nikita.Stracke commented on June 14th 19 at 20:46
Appeared NULL - anika_Da commented on June 14th 19 at 20:49
In fact, running the following code:
<?php if( is_single() ) { ?> 
 <div class="creator">
 <?php echo get_post_meta($post--->ID, 'creator', true);?>
</div>
<?php }?>

And takes no place if in the style creator no margin or padding. But if offset or field (the name of the author still would like a little separate from the name), then... there is an empty space. - Baylee_Kulas commented on June 14th 19 at 20:52
What is the complexity of checking emptiness at the same time the name of the author?
<?php if( is_single() && !empty(get_post_meta($post--->ID, 'creator', true)) ) { ?> 
 <div class="creator">
 <?php echo get_post_meta($post--->ID, 'creator', true);?>
</div>
<?php }?>
- nikita.Stracke commented on June 14th 19 at 20:55
in response to this code, the page becomes blank and displays the message:

Fatal error: Can't use function return value in write context in C:\OpenServer\domains\rockcatacombs3.ru\wp-content\themes\harmonic-child\content.php on line 53
- nikita.Stracke commented on June 14th 19 at 20:58
<?php
 $author_name = get_post_meta($post--->ID, 'creator', true);
 if( is_single() && !empty($author_name) ) {
?> 
 <div class="creator">
 <?php echo $author_name;?>
</div>
<?php }?>
- Baylee_Kulas commented on June 14th 19 at 21:01

Find more questions by tags WordPressPHP