It looks like a couple of things are out of order.
- First, I’d definitely make sure to declare the
$post
global - It’s also probably worth wrapping your logic in an
is_single()
and/oris_singular()
checks - Last, the section where you’re calculating the time as greater than 2 weeks, the current time and post date are switched. This works for me:
/**
* Enqueue a stylesheet for posts older than two weeks.
*/
function hide_meta_for_older_posts() {
if ( is_single() || is_singular() ) {
global $post;
if ( time() - strtotime( $post->post_date ) > ( 2 * WEEK_IN_SECONDS ) ) {
wp_enqueue_style( 'remove-style-meta', plugins_url( 'css/entrymetastyle.css', __FILE__ ), false, '1.0', 'all' );
}
}
}
add_action( 'wp_head', 'hide_meta_for_older_posts' );