Do not show post date on posts older than 30 days.
A member of the Genesis Facebook group asked how to hide the post date on posts older than 30 days. The solution needed a filter – right up my street.
Post info or entry meta
In Genesis I always mix up the post info and entry meta. Post info is shown before the post content and defaults to the post date, author name and the number of post comments. Entry meta, shown after post content, defaults to the post’s categories and tags. Both use shortcodes.
Since Genesis 3.2.0 these can be modified in the Customizer. Previously you needed to use PHP filters.
So, I needed to filter post info. and that uses the aptly named ‘genesis_post_info‘ filter.
Preserve Customizer settings
The code is quite simple – get the current time (in seconds since the epoch), the post date (also in seconds since epoch) and see if the difference is greater than MONTH_IN_SECONDS (a default constant from WordPress).
In my first version of the code I ignored the post info that was passed to my function and returned the default values. This did not respect the settings that the site owner had set in the Customizer.
In my second version I did a str_replace() to only remove the [ post_date] shortcode.
Simple.
Leave a Reply