# Lock Icon on Members-Only Post Titles

> Adds a small lock symbol before the titles of members-only posts in lists and archives for visitors, so they know what needs an account before clicking.

- Type: PHP
- Runs: Frontend only
- Category: [Memberships](https://wpide.com/library/category/memberships/)
- Tags: members, titles, icons
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/lock-icon-on-members-only-titles/

## Code

```php
$wpide_lock_category = 'members';

add_filter( 'the_title', function ( $title, $post_id = 0 ) use ( $wpide_lock_category ) {
    if ( is_user_logged_in() || ! $post_id || is_admin() || ! in_the_loop() || is_singular() && get_queried_object_id() === (int) $post_id ) {
        return $title;
    }

    $locked = get_post_meta( $post_id, '_wpide_members_only', true ) || ( 'post' === get_post_type( $post_id ) && has_category( $wpide_lock_category, $post_id ) );

    return $locked ? '<span class="wpide-lock" aria-label="Members only" role="img">&#128274;</span> ' . $title : $title;
}, 10, 2 );
```

## Notes

Works with posts marked members-only by the WPIDE "Members-Only Posts" snippet or placed in the members category; edit $wpide_lock_category to match yours.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Lock Icon on Members-Only 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/
