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' );
Related Posts:
- Ways to create a paid wordpress plugin?
- OpenID for WordPress 3.x? [duplicate]
- Edit plugin without hooks in functions.php
- Making plugin unique to not conflict with plugins with the same name
- Is dynamic forms/entries possible in Widget?
- Template for different category on woocommerce product [closed]
- Trying to disable plugins doens’t work
- WordPress plugin DB upgrade
- Trigger a custom wordpress plugin with a linux cron
- WordPress multiple widget in single plugin
- Have Plugin Handle Specific URLs
- Allow a userclass to save a page as a draft – but not publish w/o admin approval
- Layout shop page: resize images and columns
- Custom options page checkbox will not save, despite working with text
- Invalid shipping method, WooCommerce [closed]
- Security checking in meta_box save is reluctant?
- What causes an Unexpected HTTP Error within install plugins?
- How do I write into a file (css)
- Cache WP remote_get HTTP Response using Transients
- What is an arbitrary URL?
- How to add links in .po (language) file in wordpress?
- Is there a way to share your Facebook Page’s stream on a WordPress page or post?
- How to add equivalent of php include to one page (as plugin?)
- Allow users of my plugin to define their own shortcode rather than use mine?
- Does any one have Idea to get these functionalities with the plugin wp-multi-network
- CRUD and Frontend show from a custom table without shortcode
- Child Pages Short Code plug-in and hover capabilities?
- Timed Exam test for candidates [closed]
- There has been a critical error on your website. Please check your site admin email inbox for instructions.Learn more about debugging in WordPress [closed]
- Issue Tracker from pre exsisting table [closed]
- How to call WordPress function other files
- Does WP delete deprecated plugin/theme files on plugin/theme upgrade?
- How can I remove the WordPress-Version (?ver=5.x) from my plugin
- Settings API saved values not getting shown in the dropdownbox
- How passing values to construct function with Actions?
- correct validate and sql query
- Register google jquery gets overwritten by plugin
- How to handle forms from sidebar widgets – Processing $_POST variables using get_field_name()
- Measure and limit file uploads
- Location dependent rendering of locations? [closed]
- Why Does The `auto_update_plugin` Hook Disable Management?
- $pages = get_pages(‘child_of=’.$post->ID); Why arguments are concatenated?
- Is there a script to collect all hooks and filters provided by a plugin?
- Set up functions to be overridden without using function_exists() by short-circuiting them?
- WP RSS Aggregator plugins breaks after switch to HTTPS
- Post status doesn’t update to ‘future’ every time?
- wp_trash_post hook – problem with page updating if using wp_die
- Grab ID from post from plugin and use it to create an object
- Enqueue script: link not working in page source
- Form Plugin for Api Requests which is used via Shortcode
- i want to rewrite my custom plugin url
- Apply a Meta tag to one page only
- Can I remove an image from the Gallery without deleting it from the Media Library?
- Wp-minify doesn’t seem to minify my JS code
- eaccelerator PHP error
- Plugin Hook When New Author Added
- Looking for a good way to include php code in posts, but using special include markup rather than direct php code
- How to hide plugin submenu title in drop down in admin panel in wordpress?
- Best approach to make all tags searchable by the wordpress search function
- WordPress – Ultimate Auction for WooCommerce
- Can we hide a certain user in WP?
- Configure upload folder on WoComerce
- Show Custom Post on Frontend
- WordPress to be used more like an app?
- Hooking into the HTML header container
- WP_get_image_editor resizing images in a foreach loop
- WordPress Ajax request “Failed to load resource: the server responded with a status of 400 ()”
- WordPress Admin sub-level menu issue
- Why does WordPress use cookies for /wp-admin and /wp-content/plugins for non-admin users [duplicate]
- PHP header() not available to use in my plugin
- How to add subdomain to htaccess
- database – multiple wordpress installations using same database – can they share plugin settings?
- HyperDB failover Delay
- Add class as plugin for other plugins
- Display dashboard other than admin user
- Hidden Some Setting on Post or Page [duplicate]
- Creating themes using the one Plugin (Toolkit)
- WordPress Categories from Plugin
- How do I secure a subdomain using UCC SSL?
- Check if user is in a group of another site within multisite network [closed]
- Template from scratch: Sidebars not showing widget
- Home not showing in yoast breadcrumb
- Contact Form 7: custom validation [closed]
- Facebook meta tags not working properly on WordPress Site
- Enforce conditions only for draft posts using WyPiekacz, ignore pending and published posts
- Redirect url in plugin to somewhere else?
- is there a plugin that allow editing pages from within pages without entering admin panel?
- Trouble Removing Plugin [closed]
- Site is setup statically – how to make it content managable?
- WordPress site show white screen after updating some plugins (URGENT) [closed]
- Output plugin post like system count [closed]
- plugin translations not reflected in admin dashboard
- Elementor with system colors instead of kit colors [closed]
- Shortcode inside a redirect [closed]
- WDTException: [0]: One or more columns doesn’t have a header
- How to Add Extra Text In WordPress Title Before Post Publish
- How can I make a quotation engine like this website in WooCommerce?
- WordPress Convert queries to slashes using function.php
- 404 Error on a WordPress Website, Error disappears for a while and again appears
- ShipStation WooCommerce Integration error