• Is it possible to automatically add any icon to new posts and after several days automatically remove it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Sure. In the Loop, you need something that will get the time the post was written, and then compare it to “now”, then act on that difference.

    First, we get the post time.
    $post_time = get_the_time('U');

    Next, we get the time of last week (7 days):
    $last_week = time() - (7 * 24 * 60 * 60);

    Then we compare the two and output an image if the post time is after that last week time (meaning that it’s newer than last week):

    if ($post_time > $last_week) {
    echo '<img src="youricon.gif" />';
    }

    Simple, huh?

    Thread Starter levani01

    (@levani01)

    Thank you very much for the answer

    How must I change this code if I want to automatically remove the icon after 3 days?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Automatically add “new” icon on new posts’ is closed to new replies.