It looks like a couple of things are out of order.
- First, I’d definitely make sure to declare the
$postglobal - 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' );
Related Posts:
- ‘Global’ settings page for multisite plugin
- What Are Security Best Practices for WordPress Plugins and Themes? [closed]
- How do I show data from gravity forms in my template? [closed]
- Show a different number of posts per page depending on context (e.g., homepage, search, archive)
- How can I add a featured image to a page?
- How to customize a plugin whilst maintaining ability to upgrade
- How can I log a user out of WordPress before the page loads?
- What does a security risk in a plugin look like?
- How to generate/update a XML sitemap without plugins?
- How to assign user a role if none is present when logging in
- update_meta_user difference in i:1 and b:1, how to write b:1
- Registration Form Validation in wordpress
- Migrating a File from Plugin to Theme and changing its path → instead create a REST endpoint
- Access wordpress functions inside a plugin class
- View the source code of a 3rd party plugin? [closed]
- How to find out what blocks are added by a plugin
- Can’t access my WP dashboard: fatal error? [closed]
- allow arabic letters when register new account
- Use plugin or custom post type for game score functionality
- How to implement Sentry on WordPress? [closed]
- Need Old Version of plugins
- license check in plugin
- How to prevent users to download videos from lms website?
- How to append to title via functions.php for auto-posting plugin [duplicate]
- Page Restriction and Redirect for Particular Levels or user
- How to bypass the Easy Digital Downloads checkout process?
- Assign post format to categories
- Shrink down register_settings on Settings API
- custom payment gateway in woocommerce failed to connect to remote api server
- Parse error: syntax error, unexpected ‘new’ (T_NEW) in /misc/41/000/204/381/9/user/web/ragami.net/wp-settings.php on line 219
- Ajax call returning 0
- How to create restrict content to users (by user, not by role)
- How does WordPress know when there are plugin updates?
- Some code in shortcode function being ignored
- do_shortcode is outputting a string
- Make change in media library affect images in published articles
- Plugin allowing users to add articles to a library
- How to add Wrapper Div/container element around WordPress Widget Content
- Duplicate New User Registration notices (BuddyPress and bbPress both installed)
- How to show the number of website visitors in my theme
- Insert Message before content of after title
- Free paypal cart solution [closed]
- Which plugin can do horizontal scrolling of RSS feeds in WordPress [closed]
- Get site url and updates data, then use them
- How to integrate together a website currently hosted WordPress.com and a custom web application currently hosted on Azure?
- Problem with add_action
- Error When Trying To Login [closed]
- unable to remove malware from wp website [closed]
- Chrome Dev Tools console says every page in my blog has link to http://maps.google.com [closed]
- Get Image Having the ID [closed]
- How to create plugin auto create page wordpress?
- Scrape a webpage for image and add it to post
- How to rename WP plugin?
- Block wordpress style for my plugin admin page
- how can authors to define custom pages?
- Send a Notification to a WordPress Theme
- Gathering all Custom Post Type posts in to array/object the proper way
- Need help creating asynchronous data scraper in WordPress
- Load extra post content from plugin, after load basic post content
- Trying to get property ‘ID’ of non-object in /wp-includes/class-wp-query.php on line 4044
- How to upload large media file in chunks, without any plugin?
- Redirect unloggedin users
- WordPress asks to update a plugin already updated
- Why do I need to reload the page for WordPress to see the new custom field added with jQuery
- How to store a secret for a plugin inside public_html
- Do images in plugins automatically load?
- How to use functions found inside pluggable.php with my plugin files
- Apply only the css in my style.css file
- WordPress:Custom banner from psd trying to cut out a button area so the website link can be clicable not working
- Global $wp_admin_bar always returns null
- how to upload folders and files to google storage bucket?
- Shortcode generated widget to appear on same line as heading text and button
- WooCommerce or any other plugin: Deliver JS and CSS through CDN without using a Plugin
- How to roll back WordPress version or prevent migration from forcing update?
- WordPress arrows dissapeared strange signs
- How to prevent encoding plugin HTML output to entities?
- WordPress FTP/media directory permissions problem?
- accessibility of an object created in a plugin, from the header
- Getting error Parse error: syntax error, unexpected ‘add_filter’ (T_STRING), expecting function (T_FUNCTION)
- MobilePress plugin and WordPress 4.1 update
- Theme styling for plugins
- jquery-issue: cannot load the basic jquery
- Simple fields plugin WordPress show repeatable file field
- How to check my WordPress.org site MySQL queries generating items?
- No feedback when installing plugins or updating
- Displaying single Instagram images as a tile
- how to make a plugin secure, so any one if changes something in plugin, it just disables it self and notify us on server? [closed]
- WooCommerce – Adding notice above products on Shop Home [closed]
- JQuery UI plugin not working in IE7?
- Possible to change meta data single quotes to dobule quotes in yoast wordpress seo? [closed]
- how to know that a wordpress plugin support using API?
- Activate plugin button do nothing [closed]
- Social login authentication via wordpress rest api
- wp_enqueue_script doesn’t load JS in plugin
- AI Code For OpenAI
- How to Deobfuscate a sourcecop protected WordPress plugin?
- How to get selected variation from URL?
- Why WP CLI command is not visible in VIP CLI
- onSplit not create my custom block
- Widget saving but showing “waiting” animation [closed]