You should use get_the_time()
and not the_time()
. First one returns time and second one echoes it.
I don’t think you should do this in JS though (there is no need to, and users can always block JS and see this image anyway).
Your code could look something like this (it’s in PHP):
if ( strtotime( get_the_time('Y-m-d H:i:s') ) + 21*24*60*60 > time() ) { // if post_time + 3 weeks is greater than current time
// show your image ( the_post_thumbnail() or antyhing else you want to do)
}
Related Posts:
- JqueryUi Dialog giving Uncaught TypeError: this._addClass is not a function error
- WordPress Infinite Scroll without using any plugin
- Create Image Uploader for Widget
- WordPress Ajax always returns a 404 error
- Conditionally loading JavaScript based on the Advanced Custom Fields in the post
- WordPress customizer: load controls in a custom div
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- How to resize image on client-side before upload?
- Limit the Excerpt field in WP-Admin in words
- Passing PHP Variables to JS using Localize Script
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Customizer Show/Hide Logo and Site Title
- Understanding WordPress child theme custom JS loading
- Use different javascript files for each page on website
- Javascript code inside “” in core WordPress files .php
- Create custom blocks for bootstrap
- Click loads template via ajax
- Sending jsPDF documents to the server
- How can I add an alert (like the old javascript alerts) to my WP page?
- js file in root loading without
- AJAX request status 200 but no actual “response”
- Use menu link or onClick to set a variable
- Adding custom directory and PHP files in wordpress
- Displaying admin notices inside the block editor from rest_after_insert_{$this->post_type} hook
- Save Search System
- dynamic dependent select dropdown
- wordpress visual composer change grid builder post link
- Ajax load more button for comments wordpress
- How to pre populate a form field with a link of a current user’s author profile?
- parts of url disappear when using # inside href=”” [closed]
- PHP array to JS array to use in google map
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- Fancybox type popup window that’s not an iframe
- how to make my website secured
- How do I Import / Upload Files with jQuery AJAX?
- Noscript not working as it should in wordpress site
- How to correctly add Javascript to this PHP ‘Page Not Found’ Page?
- PHP echo inside javascript
- How to add API security keys into JS of wordpress securely
- get taxonomy thumbnail and use it as a variable in code
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- element not working in Safari [closed]
- HTML escaping data with ajax requests
- Is it save to use eval for a jQuery callback method coming from the database?
- Get html data with javascript to php array and store to wordpress database
- 2nd page displaying the exact same posts as my first page (minus the very first post)
- An audio player that showcase a random song from playlist every 24h [closed]
- How to Change CSS Colors from Custom Plugin Settings Page
- Passing the name of selected color from the custom component to `render_callback`
- How to use wordpress function wp_enqueue_script() in php?
- Get related product based on subcategory selected from category id with ID 142
- How to allow download url redirection only if user logged in WordPress site?
- wp_nav_menu not working correctly in my underscores theme
- wp_localize_script() and JavaScript namespaces
- url_to_postid returns 0
- How do i add slugs to a URL, but still redirecting to the same page
- How can I get my Media Uploader Button to function on 1 click rather than requiring 2 clicks?
- implementing a jQuery “click to expand” link in WordPress [closed]
- random reason on refresh
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- Load Javascript for a widget WordPress
- Some problems in custom widget
- Call a function in functions.php from within tags (JS)
- Hook on file upload
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- WordPress Search Ajax + Isotope + InfiniteScroll
- WordPress User Meta value variable into Google Gauge Chart
- duplicate posts with ajax load more wordpress
- How to populate a Gutenberg select field SelectControl with option value from PHP array
- Show next image in array if page is revisited by same logged user
- How to call my PHP function with AJAX ? wp_query
- Fetch Data from an external MSSQL Database in a Managed WP hosting
- Create a WordPress Contact Form to call a POST AWS API Gateway and send user data
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- separate list of programs in html/javascript coming from php
- Conditional Banners
- Update $wpdb query with AJAX
- $.ajax results in 403 forbidden
- AJAX to add to cart multiple products woocommerce
- admin-ajax.php 400 bad request – whats wrong with my code?
- WordPress load javascript file if something… (after the page is loaded)
- Target a specific container to style on WordPress storefront theme
- ACF + WP + Slick Slider Repeater Slide Group PHP not Displaying [closed]
- Default Image not showing up in Customizer for WP_Customize_Cropped_Image_Control
- How to create a radio button to alt between settings in wp_options table
- customizer live preview layout picker
- Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
- I need help implement a Javascript code into the PHP file
- Admin bar nodes
- How can I correctly POST to a WordPress page?
- if is_home(), change class of menu-item-225 of wp_nav_menu
- Load php function with AJAX on modal window
- JSON Object Value Show Undefine
- Require Credits Footer
- Adding jquery using php function
- How to hide .js files on wordpress website using php or wp plugins or any? [closed]
- Show Login Errors In WordPress/Elementor (Code “works”, but breaks site)
- How can I use AJAX in child theme template?