Site logo

Archived topic

Remove Date/updated date from a specific category posts

17 replies · Started by Rohan Verma on July 3, 2022

Viewing posts 1–15 of 18

Hello,
I want to remove the date (Meta) from all the posts from a specific category. I have shared the link to the category. I am now showing the updated date on all the posts across the site. But now I want to hide the date meta from a specific category article. Please help

Thanks and Regards

It is removing meta from the whole site.

Hi Rohan,

To clarify, are you wanting to remove the date meta only on single posts pages?

If so, kindly modify the code into something like this:

add_filter( 'generate_header_entry_meta_items', function( $items ) {

    if ( is_single() &&  in_category( 'your-category’ ) ) {
        return array_diff( $items, array( 'date' ) );
    }
	return $items;
    
} );

Kindly replace your-category with your category slug.

Kindly let us know how it goes.

No from all the posts (articles) from a specific category. Shared the link of the category in private.

So just in category pages? If so, use this instead:

add_filter( 'generate_header_entry_meta_items', function( $items ) {

    if ( is_category( 'your-category' ) ) {
        return array_diff( $items, array( 'date' ) );
    }
	return $items;
    
} );

I see. Can you try the code above again? I modified it.

As we are showing a modified date so the above php is not working. Its removing dates from the archive but inside article dates are still showing

To clarify, what specific date are you trying to remove? Can you provide a screenshot of it?

Kindly let us know.

What other functions relating to the post meta are you using on the site ?

Showing updated date instaed of publish date with this php

add_filter( 'generate_post_date_output', function( $output, $time_string ) {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished"> %2$s</time>';

if ( get_the_date() !== get_the_modified_date() ) {
$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified"> %4$s</time>';
}

$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);

return sprintf( '<span class="posted-on">%s</span> ',
$time_string
);
}, 10, 2 );

Yes, this code should work if you’re removing the date from single posts/articles of a specific category:

add_filter( 'generate_header_entry_meta_items', function( $items ) {

    if ( is_single() && in_category( 'affiliate-marketing' ) ) {
        return array_diff( $items, array( 'date' ) );
    }
	return $items;
    
} );

Hope this clarifies!

Great, it's working. Just one last thing. The data is removed from all the articles from that category that we wanted. But in the archive, it is still showing the date. Shared the link on private chat.

This archived topic is closed to new replies.