- This topic has 14 replies, 2 voices, and was last updated 3 years, 9 months ago by Joshua.
-
AuthorPosts
-
June 27, 2020 at 9:23 pm #1344136Joshua
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
June 28, 2020 at 6:32 am #1344374DavidStaffCustomer SupportHi 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 ); } } );
June 28, 2020 at 7:24 am #1344416JoshuaHey 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.
June 28, 2020 at 9:08 am #1344616DavidStaffCustomer SupportOK 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 ); } } );
June 28, 2020 at 9:19 am #1344626JoshuaHey 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.
June 28, 2020 at 9:26 am #1344635DavidStaffCustomer SupportI made an edit to the code here:
https://generatepress.com/forums/topic/change-metadata-order-on-blog-archives/#post-1344616
June 28, 2020 at 9:31 am #1344640JoshuaThat 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.
June 28, 2020 at 12:01 pm #1344741DavidStaffCustomer SupportCan you check that code again – i am not sure if the change i made updated
June 28, 2020 at 3:58 pm #1344885JoshuaI 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.
June 29, 2020 at 1:09 am #1345147DavidStaffCustomer Supportwell this is proving harder then it should be lol π
Can you add the code so i can take a look ?
June 29, 2020 at 6:08 am #1345426JoshuaSorry lol!
Code has been added again
June 29, 2020 at 6:30 am #1345450DavidStaffCustomer SupportNot 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
June 29, 2020 at 6:38 am #1345462JoshuaThat worked! Thank you so much David π
June 29, 2020 at 6:50 am #1345479DavidStaffCustomer Supporthaha awesome – great looking site π
June 29, 2020 at 9:02 am #1345844JoshuaThank you! π
-
AuthorPosts
- You must be logged in to reply to this topic.