[ad_1]
Hello,
I’m using a two-sidebar layout for my single posts and would like to put the post title and meta above the sidebars.
I’m using this PHP code to produce the meta:
// Generate author image and link in separate containers
add_filter('generate_post_author_output', function () {
$author_id = get_the_author_meta('ID');
$user_nicename = get_the_author_meta('user_nicename');
$avatar_filename = sanitize_file_name($user_nicename) . '.webp';
$upload_dir = wp_upload_dir(null, false);
$avatar_path = $upload_dir['basedir'] . '/avatars/' . $avatar_filename;
$avatar_url = $upload_dir['baseurl'] . '/avatars/' . $avatar_filename;
// Check if the local avatar file exists, otherwise use default avatar
$avatar_html = file_exists($avatar_path)
? sprintf('<img src="https://projectdmc.org/support/topic/entry-title-and-meta-above-sidebars-in-single-posts/%s" alt="Author Avatar" width="96" height="96">', esc_url($avatar_url))
: get_avatar($author_id, 48);
return sprintf(
'<div class="author-wrap">
<span class="label">Written by</span>
<a href="%1$s" title="%2$s" rel="author">
<span class="author-name" itemprop="name">%3$s</span>
</a>
</div>
<div class="author vcard">%4$s</div>',
esc_url(get_author_posts_url($author_id)),
esc_attr(sprintf(__('View all posts by %s', 'generatepress'), get_the_author())),
esc_html(get_the_author()),
$avatar_html
);
});
// Filter meta items to display date and author
add_filter('generate_header_entry_meta_items', function () {
return array(
'author',
'date',
);
});
// Filter post date to display the latest date
add_filter('generate_post_date_output', function ($output, $time_string) {
$time_string = '<span class="label">Updated on</span><time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
if (get_the_time('U') !== get_the_modified_time('U')) {
$time_string = '<span class="label">Updated on</span><time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">%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())
);
return sprintf('<div class="posted-on">%s</div> ', $time_string);
}, 10, 2);Link to post: https://shorturl.at/yDFT1
