- This topic has 6 replies, 2 voices, and was last updated 3 years, 9 months ago by Leo.
-
AuthorPosts
-
June 20, 2020 at 6:10 pm #1335855Connor R
Hi there!
I am trying to remove the link from the date and then move the category label next to it. I have written a code snippet as follows:
add_filter( 'generate_post_date_output', function( $output, $time_string ) { printf( '<span class="posted-on">%s</span>', $time_string ); }, 10, 2 ); add_filter( 'generate_post_date_output', function( $date ) { if ( is_singular() ) { return $date; } echo $date; $categories_list = get_the_category_list( ', ' ); if ( $categories_list ) { echo ' | <span class="categories">' . $categories_list . '</span>'; } } );
However, this causes the date and category to show up twice on my blog page (i.e. “June 20, 2020 | Investing June 20, 2020 | Investing).
Any help fixing this would be greatly appreciated! Thank you!
June 20, 2020 at 6:56 pm #1335874Connor RI seem to have resolved this (by accident) so it correctly displays on my blog category page. However, I’d like to do the same on my post page. Currently, my post page only shows the date (and the category is still at the bottom).
Thanks!
June 21, 2020 at 9:27 am #1336451LeoStaffCustomer SupportHi there,
You can only use the one filter once. So remove this snippet:
add_filter( 'generate_post_date_output', function( $date ) { if ( is_singular() ) { return $date; } echo $date; $categories_list = get_the_category_list( ', ' ); if ( $categories_list ) { echo ' | <span class="categories">' . $categories_list . '</span>'; } } );
Then use this these to rearrange instead:
https://docs.generatepress.com/article/generate_header_entry_meta_items/
https://docs.generatepress.com/article/generate_footer_entry_meta_items/June 21, 2020 at 11:10 am #1336561Connor RHi Leo,
I removed the code snipped you suggested and then added the PHP you mentioned:
add_filter( ‘generate_header_entry_meta_items’, function() {
return array(
‘categories’,
‘date’,
‘author’,
);
} );However, this creates two issues:
1. It duplicates the category at the top and bottom of the post/blog page.
2. How do I style this (like I had in my old PHP) so that it appears as “Date | Category?”Thanks!
June 21, 2020 at 2:18 pm #1336685LeoStaffCustomer Support1. You’d need this filter to remove the duplicate in the footer:
https://docs.generatepress.com/article/generate_footer_entry_meta_items/2. Try this filter:
https://docs.generatepress.com/article/generate_inside_post_meta_item_output/Let me know if you need help with the code ๐
June 21, 2020 at 2:23 pm #1336697Connor RLeo,
You rock! This worked:
add_filter( 'generate_footer_entry_meta_items', function() { return array( ); } ); add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) { if ( 'categories' === $item ) { return ' | '; } return $output; }, 50, 2 ); add_filter( 'generate_header_entry_meta_items', function() { return array( 'date', 'categories', ); } );
June 21, 2020 at 2:28 pm #1336702LeoStaffCustomer SupportGlad you were able to figure out the coding part – you rock as well ๐
-
AuthorPosts
- You must be logged in to reply to this topic.