Archived topic
I want to Show All Meta in One Line
23 replies · Started by Ravi Saive on June 30, 2020
I want to show all meta tags in one line in single post article only with below order:
Avatar - Author Name | Last Updated Date | Categories | Comments
Please see the image for your reference: https://ibb.co/rtYdC74
Hi there,
use this example here:
https://docs.generatepress.com/article/entry-meta-style/#example-1
just update this part of the PHP from:
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'author',
'comments-link',
'date',
);
} );
to:
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'author',
'date',
'categories',
'comments-link',
);
} );
In which file I need to update...
This would be added using one of these methods:
This would be your complete code:
add_filter( 'generate_post_author_output', function() {
return sprintf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></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' ) )
)
);
} );
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'author',
'date',
'categories',
'comments-link',
);
} );
add_filter( 'generate_footer_entry_meta_items', function( $items ) {
return array_diff( $items, [ 'categories', 'comments-link' ] );
} );
Then you'd also need to add the CSS listed on the page David linked you to. That CSS can be added using one of these methods: https://docs.generatepress.com/article/adding-css/
Hope this helps!
Thanks, David and Tom,
The given code working fine now...
I have a few more settings do like I want to display tags and next-previous navigation like the one in this screenshot: https://ibb.co/X7bFV8d
Also, I have one issue...
I have created a hook for Related Posts and added CSS to child theme style.css file, but the CSS is not working, but the same CSS working if I add in Customize Additional CSS section.
Hi there,
could you create new separate topics for those request. This one can then be marked as resolved.
Hi David and Tom,
add_filter( 'generate_post_author_output', function() {
return sprintf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></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' ) )
)
);
} );
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'author',
'date',
'categories',
'comments-link',
);
} );
add_filter( 'generate_footer_entry_meta_items', function( $items ) {
return array_diff( $items, [ 'categories', 'comments-link' ] );
} );
The above code is working great, but I just want to remove the author image only from the above code.
This is it without the avatar:
add_filter( 'generate_post_author_output', function() {
return sprintf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></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() )
)
);
} );
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'author',
'date',
'categories',
'comments-link',
);
} );
add_filter( 'generate_footer_entry_meta_items', function( $items ) {
return array_diff( $items, [ 'categories', 'comments-link' ] );
} );
Hi Tom,
Thanks, it worked, great support and great theme :)
Thanks! :)
Hi David and Tom,
I have updated the GP theme to Version: 3.1.0 and the above code is not working...
Before update - https://ibb.co/Jz6rYk1
After update - https://ibb.co/5Y6Y3Nv
Total comments count not showing after update..
Hi there,
can you share a link to a post where i can see the issue ?
Hi David,
I am testing on a staging server, so can't be possible to give access, but you can check the Live site at:
Live site - https://ibb.co/478YXkb [Where total comments count showing]
Staging Site - https://ibb.co/pxwW8tQ [where total comments count not showing]
Hi there,
Can you tell us how you've added the PHP snippet?
If you've placed the snippet inside the theme's functions.php, it would make sense why the changes applied prior to the update were removed because updating the theme overrides the edited functions.php with a fresh functions.php from 3.1.
Here's how you should be adding the PHP snippet so it's unaffected by theme updates -
https://docs.generatepress.com/article/adding-php/