[Resolved] Removing author avatar

Home Forums Support [Resolved] Removing author avatar

Home Forums Support Removing author avatar

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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&#8221; 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;
    }

    #763121
    Leo
    Staff
    Customer Support

    Hi 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;
    }
    #763538
    gedosan

    thanks – could u tweak the code and add a ‘by’ before the author please?

    #763776
    Leo
    Staff
    Customer Support

    Wouldn’t that be the default style?

    You shouldn’t need the PHP snippet at all.

    #764078
    gedosan

    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

    #764278
    Tom
    Lead Developer
    Lead Developer

    If 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 πŸ™‚

    #766729
    gedosan

    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

    #766827
    Tom
    Lead Developer
    Lead Developer

    You 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;
    }
    #767018
    gedosan

    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 πŸ™‚

    #767147
    Tom
    Lead Developer
    Lead Developer

    To 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.

    #767403
    gedosan

    Thanks Tom, all done.

    Cheers

    #767899
    Tom
    Lead Developer
    Lead Developer

    Glad I could help πŸ™‚

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.