Custom Entry Meta Error
-
I came up with the following code (based on your documentation and answers to previous support threads) to display the entry meta within a div (above the entry content and sidebars). It displays most of it, but not the author name or local avatar. Any idea why? I’d appreciate your help with this.
<?php if (is_single()) : ?> <div class="entry-meta"> <?php $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="%s" alt="Author Avatar" width="96" height="96">', esc_url($avatar_url)) : get_avatar($author_id, 48); printf( '<div class="author-wrap"> <span class="author-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 ); ?> <?php $time_string = '<span class="date-label">Published on</span><time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>'; if ( get_the_date() !== get_the_modified_date() ) { $time_string = '<span class="date-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() ) ); echo sprintf( '<span class="posted-on">%s</span> ', $time_string ); ?> </div> <?php endif; ?>
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Custom Entry Meta Error’ is closed to new replies.