• Resolved wpguillaume

    (@wpguillaume)


    Hello,

    I’m using a child theme of Twenty-Sixteen v2.0 and WordPress v2.3.5.

    Based on this page, I’ve overridden the twentysixteen_entry_meta() function from /wp-content/themes/twentysixteen/inc/template-tags.php in my child theme’s functions.php like this:

    function twentysixteen_entry_meta() {
    	if ( 'post' === get_post_type() ) {
    		$author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 49 );
    		printf(
    // Original line:
    //			'<span class="byline"><span class="author vcard">%1$s<span class="screen-reader-text">%2$s </span> <a class="url fn n" href="%3$s">%4$s</a></span></span>',
    // Modified version:
    			'<span class="byline"><span class="author vcard">%1$s</span>',
    			get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size ) //,
    //			_x( 'Author', 'Used before post author name.', 'twentysixteen' ),
    //			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    //			get_the_author()
    		);
    	}
    
    	if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
    		twentysixteen_entry_date();
    	}
    
    	$format = get_post_format();
    	if ( current_theme_supports( 'post-formats', $format ) ) {
    		printf(
    			'<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
    			sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentysixteen' ) ),
    			esc_url( get_post_format_link( $format ) ),
    			get_post_format_string( $format )
    		);
    	}
    
    	if ( 'post' === get_post_type() ) {
    		twentysixteen_entry_taxonomies();
    	}
    
    	if ( ! is_singular() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
    		echo '<span class="comments-link">';
    		comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentysixteen' ), get_the_title() ) );
    		echo '</span>';
    	}
    }

    This works fine in the large version of the website. But on mobile versions (as soon as the posts’ meta info is displayed beneath the content and not next to it), the ” / ” separators are removed and the publish date gets “stuck” to the categories.

    Could you point me to the next code modification to solve this? Or otherwise give a nicer solution to remove only the author name from posts?

    Thank you! ??

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi, I don’t see any / separator for the post meta info on a desktop version of the site. I do see that the spacing on the content for the post meta is rather scrunched up on mobile and not entirely readable.

    How are you wanting the content to display exactly on mobile for the post meta?

    Thread Starter wpguillaume

    (@wpguillaume)

    Hi @jarretc, thank you for your answer,

    Indeed, there are no / separators on desktop version, as information is displayed on separate lines.
    On mobile, I’d like it to show up as seen on the Twenty-Sixteen demo site, just without the author name:
    https://twentysixteendemo.wordpress.com/2015/11/27/image-post-format/

    There’s an extra / at the end of the line on this demo site though, for some reason. It doesn’t show up on my site (I’ve disabled the piece of code for you to see how it should look).

    For instance, on mobile, on just one line, there should be:
    <round avatar image> PublishDate / Category1, Category2

    Ok, for your modified version of the code, you can either remove a span tag such as

    if ( 'post' === get_post_type() ) {
    			$author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 49 );
    			printf(
    				'<span class="author vcard">%1$s</span>',
    			get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size ) //,
    //			_x( 'Author', 'Used before post author name.', 'twentysixteen' ),
    //			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    //			get_the_author()
    			);
    		}

    Or you can add another <span in there such as

    if ( 'post' === get_post_type() ) {
    			$author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 49 );
    			printf(
    				'<span class="byline"><span class="author vcard">%1$s</span></span>',
    			get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size ) //,
    //			_x( 'Author', 'Used before post author name.', 'twentysixteen' ),
    //			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    //			get_the_author()
    			);
    		}

    Either way you choose to do it, I think you’ll need to then use CSS to hide the / such as

    .entry-footer span:first-child:after {
    	content: "";
    }
    Thread Starter wpguillaume

    (@wpguillaume)

    I had indeed removed one too many </span> tags in my “modified version”.
    Keeping the byline class, and removing commented lines for clarity, the code now looks like this, like your second suggestion:

    if ( 'post' === get_post_type() ) {
    	$author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 49 );
    	printf(
    		'<span class="byline"><span class="author vcard">%1$s</span></span>',
    		get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size )
    	);
    }

    And the CSS bit was indeed necessary, to remove the first / separator.

    Thanks a lot, problem solved!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Remove author name but keep avatar, publish date and categories’ is closed to new replies.