Archived topic
(Date) by (Author) – (Categories) in line
12 replies · Started by Milos on September 6, 2020
Hi Tom, I’m also trying to set meta data in one single line, like in this post https://generatepress.com/forums/topic/all-meta-in-one-single-line/, but after adding a snippet it tells me Cannot redeclare function generate_posted_on. Can you help me? Thanks Milos
Hi there,
that is a really old topic. Maybe this example would be a better place to start:
https://docs.generatepress.com/article/entry-meta-style/#example-1
Thanks David, when I use variant 1, I don't see the categories in that row and the date at the end, would it be possible to do it as I request?
Date - author - category
And I have one more question. Please, as I turn off the display of categories in the next section - for example, below the image in the archive, it will be enough for me to have everything once using a line, thanks a lot.
Try this:
add_filter( 'generate_header_entry_meta_items', function( $items ) {
if ( is_single() ) {
// Set meta for single post
$items = array(
'date',
'author',
'categories',
);
} else {
// Set meta for archives
$items = array(
'date',
'author',
);
}
return $items;
} );
This will set the Meta - Date|Author|Categories for single posts and Date|Author on archives.
Ok, thats good, but how can I remove default location "category"? Now I have it on the web 2x.
You can add this snippet to remove the Categories from the footer meta:
add_filter( 'generate_footer_entry_meta_items', function( $items ) {
return array_diff( $items, [ 'categories' ] );
} );
Thanks David, now "archive" is ok, but "single post" has no meta tags, I use this procedure https://generatepress.com/forums/topic/move-author-date-to-the-bottom-after-content / page / 2 / so it is possible that there is a problem. If I turn it on above, it's fine, but I'd like to have the date of the author, etc. at the end of the post, thanks a lot.
Just to be clear.
On the Archive the current layout is correct.
On Single Post you wish to move all the entry meta - Date|Author|Categories to the Footer ?
exactly
Hi there,
Isn't the default for archives "date by author"? Then you can disable the categories by going to Customize > Layout > Blog and un-checking the categories option for single posts.
Then, you should just be able to target single posts like this without the need for any other functions:
add_filter( 'generate_footer_entry_meta_items', function( $items ) {
if ( is_single() ) {
$items = array(
'date',
'author',
'categories',
'post-navigation',
);
}
return $items;
} );
Now is everything very nice bautiful :) thanks
You're welcome :)