Reputation: 922
I want to display author name for "author meta tag" , I used following code to do this, But I always get an empty string for that:
$fname = get_the_author_meta('first_name');
$lname = get_the_author_meta('last_name');
$author = trim( "$fname $lname" );
if ( $author ) { ?>
<meta name="author" content="<?php echo $author; ?>">
<?php } ?>
How can I get the current displayed page/post author name ?
Thank you
Upvotes: 0
Views: 1684
Reputation: 1172
Ok, got it. The name of the author is actually displayed by php in your HTML page, but it's encapsulated in a meta tag, which is only used in the head part of your page, and don't produce any visible output for the user.
Try to use a div tag instead of the meta one, and make sure you are writing inside the body part of your page.
$fname = get_the_author_meta('first_name');
$lname = get_the_author_meta('last_name');
$author = trim( "$fname $lname" );
if ( $author ) { ?>
<div>Author: <?php echo $author; ?></div>
<?php } ?>
Upvotes: -1
Reputation: 1172
You need to check first you if you get correct values from the get_the_author_meta(). So, you will know if the problem come from the trim/condition part, or from wordpress itself. To do this, add in your code :
echo "Here is my result : ".get_the_author_meta('first_name')." ".get_the_author_meta('last_name');
Once this test done, i'm sure you'll need to edit your question.
Take this answer as a general advice for debugging, more than a solution for your problem.
Upvotes: 0