# Custom Message on Password-Protected Posts

> Replaces the standard "This content is password protected" sentence with your own message, for example explaining how to get the password.

- Type: PHP
- Runs: Run everywhere
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: password, protected, message
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/password-form-message/

## Code

```php
// Message shown above the password field.
$wpide_password_message = 'This page is for clients only. Enter the password from your welcome email to continue.';

add_filter( 'the_password_form', function ( $output ) use ( $wpide_password_message ) {
    $result = preg_replace( '/<p>.*?<\/p>/s', '<p>' . str_replace( array( '\\', '$' ), array( '\\\\', '\\$' ), wp_kses_post( $wpide_password_message ) ) . '</p>', $output, 1 );

    return null === $result ? $output : $result;
} );
```

## Notes

Basic HTML such as links is allowed in the message.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Custom Message on Password-Protected Posts" 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/
