[Resolved] Change metadata order on blog archives

Home Forums Support [Resolved] Change metadata order on blog archives

Home Forums Support Change metadata order on blog archives

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1344136
    Joshua

    Hi,

    I’d like to change where the metadata appears on the blog archive and category archive pages.

    Currently the metadata (the category specifically) appears under the excerpt, for example: https://joshuamayo.com/blog/

    I’d like the metadata to appears above the title instead (after the thumbnail).

    I found this code that Tom posted on a different topic while trying to do research:

    
    add_filter( 'generate_show_categories', '__return_false' );
    
    add_action( 'generate_after_entry_title', function() {
        $categories_list = get_the_category_list( ', ' );
    
        if ( $categories_list ) {
            printf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
                esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ),
                $categories_list
            );
        }
    } );

    But I have no idea how to alter it to make it work for my needs. Any help is greatly appreciated! πŸ™‚

    Joshua

    #1344374
    David
    Staff
    Customer Support

    Hi there,

    first off you can use generate_header_entry_meta_items filter to set the entry meta to display your categories:

    add_filter( 'generate_header_entry_meta_items', function( $items ) {
        if ( !is_single() ) {
            $items = array(
                'categories',
            );
        } return $items;
    } );

    Then you can unhook the entry meta and hook it in above the title with this snippet:

    add_action( 'wp', function() {
        if (!is_single() ) {
            remove_action( 'generate_after_entry_title', 'generate_post_meta' );
            add_action( 'generate_before_entry_title', 'generate_post_meta', 15 );
        }
    } );
    #1344416
    Joshua

    Hey David,

    Thank you for your reply as always!

    I added this code to my functions.php and it doesn’t seem to change the position of the categories.

    I realize I may have been using the wrong terminology when describing the metadata. I don’t actually think I want to move the metadata, but instead just the blog categories location to above the title (and below the thumbnail).

    I did notice that when I go to customizer > layout > blog section and turn on the “Display post author” or “Display post date” that the category appears above the title, however, the category that is currently below the excerpt still displays. And when I try to turn that off by unchecking “Display post categories” both that category and the category that appears above the title disappear.

    #1344616
    David
    Staff
    Customer Support

    OK remove any of the code above and try this instead:

    add_action( 'wp', function() {
        if (!is_single() ) {
            remove_action( 'generate_after_entry_content', 'generate_footer_meta', 10 );
            add_action( 'generate_before_entry_title', 'generate_footer_meta', 5 );
        }
    } );
    #1344626
    Joshua

    Hey David,

    I removed the previous code and added the new code, but it still seems to not have an affect on the category position.

    I also tried removing all the other code in my functions.php just in case there was something interfering with it, but to no avail.

    #1344635
    David
    Staff
    Customer Support
    #1344640
    Joshua

    That got rid of the category taxonomy completely. If I turn on “Display post date”, oddly it appears in the right spot. However, when I turn on that option it also shows the category below the title. I left it turned on so you could see what I’m talking about.

    #1344741
    David
    Staff
    Customer Support

    Can you check that code again – i am not sure if the change i made updated

    #1344885
    Joshua

    I updated the code, it almost works. It’s still showing the double category. When I go to customizer > layout > blog and uncheck “Display post date”, both categories disappear, even if ” Display post categories” is checked.

    #1345147
    David
    Staff
    Customer Support

    well this is proving harder then it should be lol πŸ™‚

    Can you add the code so i can take a look ?

    #1345426
    Joshua

    Sorry lol!

    Code has been added again

    #1345450
    David
    Staff
    Customer Support

    Not your fault – i think i am having a bad meta day lol

    So lets try this.
    Remove that code.
    Add this:

    // Set entry meta to category only 
    add_filter( 'generate_header_entry_meta_items', function( $items ) {
        if ( !is_single() ) {
            $items = array(
                'categories',
            );
        } return $items;
    } );
    
    // Return no footer meta
    add_filter( 'generate_footer_entry_meta_items', function( $items ) {
        if ( !is_single() ) {
            $items = array(
                '',
            );
        } return $items;
    } );
    // Move entry meta above title
    add_action( 'wp', function() {
        if (!is_single() ) {
            remove_action( 'generate_after_entry_title', 'generate_post_meta' );
            add_action( 'generate_before_entry_title', 'generate_post_meta', 15 );
        }
    } );

    And make sure you have the Date or Author meta set to display

    #1345462
    Joshua

    That worked! Thank you so much David πŸ™‚

    #1345479
    David
    Staff
    Customer Support

    haha awesome – great looking site πŸ™‚

    #1345844
    Joshua

    Thank you! πŸ™‚

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