Change the default 10-day expiration for the password protected pages cookie

I’m trying to change the default 10-day expiration for the cookie that allows a user to repeatedly view the content on a password-protected WP page without having to re-enter the page password during the default 10-day period. Rather than 10 days, I’d like to re-set the expiration to 30 seconds.

The WP code reference is here:

apply_filters( ‘post_password_expires’, int $expires )

This is what I have tried, without success:

function custom_post_password_expires() {
return time() + 30; // Expire in 30 seconds
}
apply_filters(‘post_password_expires’, ‘custom_post_password_expires’);

I’ve read the answers to previous similar questions, and none seem to apply or to provide a solution that works with the current version of WP. I suspect that the correct answer is very simple, but so far I’m not finding it. (Note: I am not an advanced developer, so I’d appreciate replies that are easy to understand 🙂

Thanks.

Read more here:: Change the default 10-day expiration for the password protected pages cookie

Leave a Reply

Your email address will not be published. Required fields are marked *