- This topic has 17 replies, 3 voices, and was last updated 3 years, 9 months ago by
Fernando.
-
AuthorPosts
-
July 3, 2022 at 12:17 am #2271533
Rohan Verma
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 helpThanks and Regards
July 3, 2022 at 3:39 am #2271645David
StaffCustomer SupportHi there,
try this:
add_filter( 'generate_header_entry_meta_items', function( $items ) { if ( is_category( 'your-category' ) || in_category( 'your-category' ) ) { return array_diff( $items, array( 'date' ) ); } } );More info on that filter here:
https://docs.generatepress.com/article/generate_header_entry_meta_items/#removing-an-item
July 3, 2022 at 10:56 pm #2272314Rohan Verma
It is removing meta from the whole site.
July 3, 2022 at 11:28 pm #2272337Fernando Customer Support
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-categorywith your category slug.Kindly let us know how it goes.
July 3, 2022 at 11:30 pm #2272338Rohan Verma
No from all the posts (articles) from a specific category. Shared the link of the category in private.
July 3, 2022 at 11:35 pm #2272341Fernando Customer Support
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; } );July 4, 2022 at 12:08 am #2272357Rohan Verma
It giving error: https://ibb.co/pxkWxQ9
July 4, 2022 at 12:13 am #2272359Fernando Customer Support
I see. Can you try the code above again? I modified it.
July 4, 2022 at 12:17 am #2272363Rohan Verma
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
July 4, 2022 at 12:31 am #2272367Fernando Customer Support
To clarify, what specific date are you trying to remove? Can you provide a screenshot of it?
Kindly let us know.
July 4, 2022 at 4:48 am #2272531Rohan Verma
Here is a screenshot: https://pasteboard.co/9ZuZERnn3jJg.jpg. We want to remove the date from all the articles of a specific category.
July 4, 2022 at 6:00 am #2272600David
StaffCustomer SupportWhat other functions relating to the post meta are you using on the site ?
July 5, 2022 at 12:54 am #2273424Rohan Verma
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 );July 5, 2022 at 1:09 am #2273437Fernando Customer Support
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!
July 5, 2022 at 1:19 am #2273441Rohan Verma
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.
-
AuthorPosts
- You must be logged in to reply to this topic.