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.
Opens WPIDE on
Code
$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">🔒</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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.