[Resolved] Show Categories (Meta Information) of a Post using Sections

Home Forums Support [Resolved] Show Categories (Meta Information) of a Post using Sections

Home Forums Support Show Categories (Meta Information) of a Post using Sections

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #990816
    Mirko

    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.

    #991216
    Tom
    Lead Developer
    Lead Developer

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

    #991312
    Mirko

    Hi Tom, thanks for your reply.

    Ah ok, does make sense.

    No it would not negatively affect any other posts πŸ™‚

    #991724
    Tom
    Lead Developer
    Lead Developer

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

    #991766
    Mirko

    Works πŸ™‚ Thank you Tom!

    #991973
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

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