October 11

Add A New Icon To Posts Less Than 30 Days Old

Sometimes, we build sites on WordPress that are not updated daily sometimes not even weekly. For example, an affiliate blog where affiliate managers share new tools, new announcements and other resources. You’d want to draw attention to these posts quickly. All you need is this.

<?php if ( (current_time(timestamp) - get_the_time('U') - (get_settings('gmt_offset') * 3600) ) < (30*(60*60*24))) { ?><span style="color: #960000; font-weight: bold;">NEW!</span><?php } ?>

Notes:

  1. You can use this in your templates, right next to the title of archives or home page, just make sure it is inside The Loop.
  2. You can use an image if you prefer
  3. If you want to change the duration, just change the number of days. Here’s how.
(60*60*24) in the code above = 1 day (60 seconds * 60 minutes * 24 hours)
30*(60*60*24) = 1 day * 30 which equals 30 days
15*(60*60*24) = 15 days and so on. It’s just simple math.

Tags


You may also like

Force cPanel Password Reset

Force cPanel Password Reset
Leave a Reply
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Get in touch

Name*
Email*
Message
0 of 350