Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Genesis Hide Old Post Dates - Do not show post date on posts older than 30 days.
<?php
/*
Plugin Name: Genesis Hide Old Post Dates
Plugin URI: https://www.damiencarbery.com/2021/02/hide-old-post-dates-in-genesis/
Description: Do not show post date on posts older than 30 days.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.2
*/
function dcwd_hide_old_post_info($post_info) {
$now = time(); // Get current time in "seconds since epoch" format.
$date = get_the_date( 'U' ); // Get post date in "seconds since epoch" format.
// If post is more than 30 days old then change the post info to remove post date.
if ( $now - $date > MONTH_IN_SECONDS ) {
$post_info = str_replace( '[post_date]', '', $post_info );
}
return $post_info;
}
add_filter('genesis_post_info', 'dcwd_hide_old_post_info');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment