- This topic has 11 replies, 3 voices, and was last updated 4 years, 5 months ago by
Tom.
-
AuthorPosts
-
December 21, 2018 at 3:24 am #762781
gedosan
Hi there
I’m using a snippet to format my ‘post info’ below my page title. I’d like to remove the avatar, so it’s just AUTHOR NAME | DATE without the author pic.
Here’s the snippet if it makes things quicker:
add_filter( ‘generate_post_author’, ‘__return_false’ );
add_filter( ‘generate_show_comments’, ‘__return_false’ );
add_filter( ‘generate_post_date_output’, ‘tu_fancy_byline’ );
function tu_fancy_byline( $date ) {
printf( ‘ <span class=”byline”>%1$s</span>’,
sprintf( ‘<span class=”author vcard” itemtype=”http://schema.org/Person” itemscope=”itemscope” itemprop=”author”>%4$s<span class=”author-name” itemprop=”name”>%3$s</span></span>’,
esc_url( get_author_posts_url( get_the_author_meta( ‘ID’ ) ) ),
esc_attr( sprintf( __( ‘View all posts by %s’, ‘generatepress’ ), get_the_author() ) ),
esc_html( get_the_author() ),
get_avatar( get_the_author_meta( ‘ID’ ) )
)
);if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo ‘<span class=”comments-link”>’;
comments_popup_link( __( ‘Leave a comment’, ‘generatepress’ ), __( ‘1 Comment’, ‘generatepress’ ), __( ‘% Comments’, ‘generatepress’ ) );
echo ‘</span>’;
}echo $date;
}December 21, 2018 at 8:42 am #763121Leo
StaffCustomer SupportHi there,
Try this:
add_filter( 'generate_post_author', '__return_false' ); add_filter( 'generate_show_comments', '__return_false' ); add_filter( 'generate_post_date_output', 'tu_fancy_byline' ); function tu_fancy_byline( $date ) { printf( ' <span class="byline">%1$s</span>', // WPCS: XSS ok, sanitization ok. sprintf( '<span class="author vcard" itemtype="https://schema.org/Person" itemscope="itemscope" itemprop="author"><a class="url fn n" href="%1$s" title="%2$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%3$s</span></a></span>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), /* translators: 1: Author name */ esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ) ) ); if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { echo '<span class="comments-link">'; comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) ); echo '</span>'; } echo $date; }
December 22, 2018 at 3:22 am #763538gedosan
thanks – could u tweak the code and add a ‘by’ before the author please?
December 22, 2018 at 9:45 am #763776Leo
StaffCustomer SupportWouldn’t that be the default style?
You shouldn’t need the PHP snippet at all.
December 23, 2018 at 3:40 am #764078gedosan
i thought the default was ‘published date’ not ‘last updated’ date though?
Also, just noticed on mobile it looks really big. Can u share with me the CSS to bring it down in size a touch too please?
Thanks
December 23, 2018 at 8:49 am #764278Tom
Lead DeveloperLead DeveloperIf all you’re wanting to do is show the updated date, you can use CSS and no PHP at all: https://docs.generatepress.com/article/show-the-updated-post-date/
Let me know π
December 27, 2018 at 7:07 am #766729gedosan
Thanks Tom – I still need the PHP snippet to inject the author (so its author | date) right?
– I wanted to add the word ‘by’ so it’s ‘by author | date’
– I wanted the CSS so I can reduce the size of both (especially on mobile, they show up huge)Thanks guys
G
December 27, 2018 at 9:38 am #766827Tom
Lead DeveloperLead DeveloperYou shouldn’t need PHP for that.
You just need to do this:
.entry-header .entry-meta { display: flex; } .entry-header .entry-meta .byline { order: -10; } .entry-header .entry-meta .byline:after { content: " | "; padding-right: 5px; }
December 27, 2018 at 1:13 pm #767018gedosan
Thanks Tom, that works. How do I stop the date being a hyperlink? Also the author link just goes back to the homepage?
Thanks for all the help π
December 27, 2018 at 4:42 pm #767147Tom
Lead DeveloperLead DeveloperTo remove the link, this should help: https://docs.generatepress.com/article/generate_post_date_output/#remove-link-from-date
The author link should take you to the author archives, by default.
December 28, 2018 at 1:36 am #767403gedosan
Thanks Tom, all done.
Cheers
December 28, 2018 at 10:15 am #767899Tom
Lead DeveloperLead DeveloperGlad I could help π
-
AuthorPosts
- You must be logged in to reply to this topic.