Archived topic
Removing date on sticky blog post
5 replies · Started by Emily on August 26, 2022
Hello. Thank you for such an awesome theme!! It's the only one I use. :)
Can you provide a little code snippet to hide the date on all sticky blog posts? The google was unable to provide an answer. If it's easier to just hide all the meta, that works, too.
Thank you!!
Hi there,
Any chance you can link us to the page in question?
You can use the private information field:
https://docs.generatepress.com/article/using-the-premium-support-forum/#private-information
Let me know :)
Link to site in private info. The home page has a sticky post. We're using WP Show Posts for the listing, but I'm hoping for a site-wide solution because we don't want it to appear anywhere at all.
Hi Emily,
Add this PHP code to your site so it adds the sticky-post class to the sticky posts.
add_filter( 'post_class', 'sticky_post_class', 10, 2);
function sticky_post_class( $classes, $class) {
if (is_sticky()) {
$classes[] = 'sticky-post';
return $classes;
}
return $classes;
}
You can use either method mentioned here to add PHP: https://docs.generatepress.com/article/adding-php/
Then we can use this CSS to target the sticky posts and hide the date:
.sticky-post time.wp-show-posts-entry-date.published, .sticky-post .wp-show-posts-separator {
display: none;
}
Adding CSS: https://docs.generatepress.com/article/adding-css/
Awesome! All set up. Thank you very much.
You are welcome :)