Home  »  CodeGuidesLibrariesProgrammingSnippetsTechnology   »   Login User Programmatically in WordPress

Login User Programmatically in WordPress

Posted: May 11, 2022 | by Site Host

WordPress code snippet to login user programmatically in your functions.php file:

clean_user_cache( $user_id );
wp_clear_auth_cookie();
wp_set_current_user( $user_id );
wp_set_auth_cookie( $user_id, true, false );

$user = get_user_by( 'id', $user_id );
update_user_caches( $user );

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Share it!

See also  How to Invert Columns Using CSS and Flex