• wpdkc

    (@wpdkc)


    On my webpage I want the visitors to log in to the password protected pages at each site visit.

    I have updated wp-login.php according to “https://developer.ww.wp.xz.cn/reference/hooks/post_password_expires/”, setting the value to “0”, but it does not work. The cookie does not seem to work like a seesion cookie. I can close the browser and when I open it again, I am able to go the protected pages without retyping the password.

    Is there someting wrong with the description in the link?

    Can forcing a log in at each visit be achieved in another way?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You should not modify wp-login.php itself. Add a filter to modify the expiration value. For example, this works for me in functions.php:

    function Modif_expir_cookie( $time ) { 
      return 0;
    }
    add_filter('post_password_expires', 'Modif_expir_cookie' );

    (modified from the user note on the doc page you linked)

    Thread Starter wpdkc

    (@wpdkc)

    Hi, thanks for the reply.

    I assume that the functions.php you are refering to is the one related to the theme and not the core one?

    Should the code just be added to the end of the file, or could it maybe even be added in built-in CSS editor?

    Moderator bcworkz

    (@bcworkz)

    Apologies for lack of clarity. Yes, functions.php of the theme. However, if your theme is subject to periodic updates, you should not modify it either. Instead, you could create a child theme and place PHP code in its functions.php.

    Creating a child theme is a bit of a fuss. If you are not modifying templates and just adding PHP code, it’s actually easier to create a small custom plugin to contain the code. You can also add any other custom code you decide to use in the future to the same plugin.

    The code in question is PHP and will only create a syntax error if placed within the customzer’s Additional CSS section. There are established “snippets” plugins that will let you safely add PHP snippets to the site. Personally I don’t see the point since creating a custom plugin is relatively easy, but some people prefer these snippets plugins or they wouldn’t be used in many thousands of installations.

    Thread Starter wpdkc

    (@wpdkc)

    Thanks for the reply. I will try looking into creating a custom plugin.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Password cookie expiry’ is closed to new replies.