# "New" Badge on Recent Post Titles

> Adds a small "New" label next to the titles of posts published in the last few days on your blog and archive pages.

- Type: PHP
- Runs: Frontend only
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: badge, posts, archives
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/new-badge-on-recent-posts/

## Code

```php
// Posts newer than this many days get the badge.
$wpide_new_badge_days = 7;
// Badge text.
$wpide_new_badge_text = 'New';

add_filter( 'the_title', function ( $title, $id = 0 ) use ( $wpide_new_badge_days, $wpide_new_badge_text ) {
    if ( is_admin() || is_feed() || is_singular() || ! in_the_loop() || ! $id || 'post' !== get_post_type( $id ) ) {
        return $title;
    }

    $published = (int) get_post_time( 'U', true, $id );

    if ( $published && time() - $published < $wpide_new_badge_days * DAY_IN_SECONDS ) {
        $title .= ' <span class="wpide-new-badge" style="display:inline-block;margin-left:.4em;padding:.1em .45em;font-size:.6em;vertical-align:middle;line-height:1.4;border-radius:3px;background:#d63638;color:#fff;">' . esc_html( $wpide_new_badge_text ) . '</span>';
    }

    return $title;
}, 10, 2 );
```

## Notes

Change the number of days or the label text. Themes that use the title inside an HTML attribute will show the word as plain text there.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""New" Badge on Recent Post Titles" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
