Archived topic
Show Categories (Meta Information) of a Post using Sections
5 replies · Started by Mirko on August 22, 2019
Hi,
I am using sectinons on my posts. I want to show the meta infos on the top of the post. To do this I added the code I found on another support ticket here (https://generatepress.com/forums/topic/display-post-meta-in-sections/page/2/) and added the short code to my post. It works and shows the author name and the post date, but not the categories of the post, even if I enable "categories" in Customize > Layout > Blog.
Can you please help me with this? Thanks in advance.
Hi there,
That's because categories display below the post by default.
If we add code to display them along with the other post meta at the top, will it negatively affect your other posts?
Let me know :)
Hi Tom, thanks for your reply.
Ah ok, does make sense.
No it would not negatively affect any other posts :)
Try this PHP:
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'author',
'date',
'categories',
);
} );
add_filter( 'generate_footer_entry_meta_items', function( $items ) {
return array_diff( $items, [ 'categories' ] );
} );
Let me know :)
Works :-) Thank you Tom!
You're welcome :)