1

I have menu items that are set to be shown/hidden depending on if the user is logged in. I would like to change the default cookie name that WP looks for to determine login status.

My cookie name is _example and has a value of 1 when user is logged in.

I have tried define( 'TEST_COOKIE', '_example' ); in wp-config.php, but that didn't seem to do the trick.

How can I replace the default cookie name?

Note: I do not need to identify which user is logged in, only whether or not it is true to show/hide menu items. _example has a value of 1 if logged in, otherwise _example is not present or 0.

6
  • What does the cookie name have to do with hiding/showing menu items if the user's logged in? WordPress has functions for that sort of check that doesn't require hard-coding a single specific cookie name. – Jacob Peattie Jul 16 '18 at 13:22
  • Because I am using an external site (subdomain) where the user logs in. They aren't using the WP login. – Fid Jul 16 '18 at 13:25
  • 1
    That doesn't mean you have to change the cookie name, and it's not how most SSO works either – Tom J Nowell Jul 16 '18 at 13:31
  • I have to change the name so that WP can identify logged in status and show/hide menu items. – Fid Jul 16 '18 at 13:34
  • to use an external authentication system, it's better to use this filter developer.wordpress.org/reference/hooks/authenticate – mmm Jul 16 '18 at 13:41
1

Cookies do not indicate login status. Even if the cookie is not expired it is possible to terminate the session on admin side, and obviously, just the fact that there is a cookie do not mean that the information in it will authenticate. Sounds like you need an actual SSO solution.

0

Did you try? This is the answer of how to change logged in cookie name :)

define( 'COOKIEHASH',           md5( 'http://example.tld' )    ); 
define( 'LOGGED_IN_COOKIE',     'wpse_logged_in_' . COOKIEHASH );
1
  • Please edit your answer, and add an explanation: why could that solve the problem? – fuxia Jul 16 '18 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.