I am trying to show meta contents on single page. But get_the_author()
is not showing. The result of the below code is
Written by on July 14, 2015
and it is supposed to show
Written by admin on July 14, 2015
Anyone knows what I am missing? Here is the code:
function mano_posted_on() {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
if (get_the_time('U') !== get_the_modified_time('U')) {
$time_string.= '<time class="updated" datetime="%3$s">%4$s</time>';
}
$time_string = sprintf(
$time_string,
esc_attr(get_the_date('c')),
esc_html(get_the_date()),
esc_attr(get_the_modified_date('c')),
esc_html(get_the_modified_date())
);
printf(
__('<span class="byline">Written by %1$s</span><span class="posted-on">on %2$s</span>', 'mano'),
sprintf(
'<span class="author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>',
esc_url(get_author_posts_url(get_the_author_meta('ID'))),
esc_html(get_the_author())
),
sprintf(
'<a href="%1$s" rel="bookmark">%2$s</a>',
esc_url(get_permalink()),
$time_string
)
);
}
To return to PHP rather than displaying, use get_the_author(). https://codex.wordpress.org/Function_Reference/the_author
So try changing get_the_author()
to the_author()
.
Try this :
echo get_the_author($post->author_id);
Make $post as global.
so it will look like on top of file :
global $post;