Add "Sign in with Microsoft" button to a WordPress login form
Use this guide if you want to add a Sign in with Microsoft button to your (default or custom) WordPress login form. Doing so would give your users the choice of signing into your website either with their WordPress account or with their Microsoft (work, school or personal) account when you are have the (PROFESSIONAL, PREMIUM or INTRANET edition of the) WordPress + Office 365 plugin installed.
The plugin already offers a so-called Dual login capability (see https://www.wpo365.com/redirect-to-login/ for details). This would make sure that users can choose how they would like to sign into your WordPress website. However, the following additional configuration allows to suppress the default Dual login message just above the login box. Instead, a Sign in with Microsoft button will be visible at the bottom of the login form, just after the password field.
Before you start
- You must already have configured the single sign-on capability of the WordPress + Office 365 plugin.
- You are an Administrator for your WordPress website.
Adding the button to the login Form
To add the button to the login file, you should edit your (child) theme's functions.php file and add an action that hooks into the login_form hook and a function that will be executed whenever the hook fires.
Configuring Dual login
Finally, perform the following steps to enable Dual login but hide the default Dual login message. Without Dual login, users will be sent directly to Microsoft and would not have the choice to sign into your website with their WordPress account.
- Navigate to WP Admin > WPO365 > Login / Logout and check Dual login V2 as well as Hide SSO Link.