简体   繁体   中英

Facebook login for wordpress without a plugin

I'm providing a custom login page for the website visitors and would like to include the Login with Facebook button such that the application checks if the user email is registered, and if so it will log the user in.

using wp_signon I can log a user in by providing the email and password, but in that case I don't have a password for the user, so is there a way I can provide a Facebook login button without using plugins?

If you want to do it without plugin then you need to implement OAuth by yourself. You can use this article as reference to create a facebook login button for your theme from scratch without plugin.

WordPress Frontend Facebook Login

Use this code and replace the APP ID with and your Domain...

<html>
    <head>
      <title>Login with Facebook</title>
    </head>
    <body>

      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          FB.init({
        appId      : 'YOUR_APP_ID', // App ID
        channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true  // parse XFBML
      });
    };
    // Load the SDK Asynchronously
    (function(d){
       var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
       if (d.getElementById(id)) {return;}
       js = d.createElement('script'); js.id = id; js.async = true;
       js.src = "//connect.facebook.net/en_US/all.js";
       ref.parentNode.insertBefore(js, ref);
     }(document));
  </script>

  <div class="fb-login-button">Login with Facebook</div>

</body>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM