Site logo

Archived topic

Move posts date to the bottom on front/blog page only

5 replies · Started by Piotr on September 30, 2021

Viewing posts 1–6 of 6

Hi,
I'd like to slightly change posts appearance on my website (www.rockmetalnews.pl). What I want to do is to add post excerpts and then move posts date to the bottom of the posts area on my front/blog page. I found this Code Snippets solution in another topic:

`add_filter( 'generate_header_entry_meta_items', function( $items ) {
return array_diff( $items, array( 'date' ) );
} );

add_filter( 'generate_footer_entry_meta_items', function( $items ) {
$items[] = 'date';

return $items;
} );

This code works perfect, but unfortunatelly affects single post pages as well. I don't want that. Is there any way to change this and run this code on front/blog page only? I'm looking forward to your reply. Thank you!
Sincerely,
Piotr

Hi Leo,
thank you for your answer! I used the conditional tag, but now post date disappeared from my single post page. This is my code:

`add_filter( 'generate_header_entry_meta_items', function( $items ) {
if(is_home() || is_archive() )
return array_diff( $items, array( 'date' ) );
} );

add_filter( 'generate_footer_entry_meta_items', function( $items ) {
if(is_home() || is_archive() )
$items[] = 'date';

return $items;
} );

Did I something wrong? Thank you!
Sincerely,
Piotr

Hi Piotr,

Try this:

add_filter( 'generate_header_entry_meta_items', function( $items ) {
    if (is_home() || is_archive() ){
   	return array_diff( $items, array( 'date' ) ); 
    }
    return  $items;
} );

add_filter( 'generate_footer_entry_meta_items', function( $items ) {
    if(is_home() || is_archive() ){
        $items[] = 'date';
    }
    return $items;
} );

Let me know :)

Hi Ying,
thank you for your answer! The code works like a charm. You have helped me a lot. GeneratePress Support is the best, as always :)
Sincerely,
Piotr

Glad to hear that :)

And you are very welcome!

This archived topic is closed to new replies.