I have a demo site where I want public users to login with Facebook only.
Admins will login with the standard WordPress login.
So I have added a Facebook login button to the WordPress login screen.
I don’t want to confuse the users and let them see the WordPress username and password text fields i.e. I want to hide those 2 input fields.
Is there a way to hide the WordPress username and password text fields and then allow an admin to make them visible when they want to login?
So maybe, click a link which will then make the WordPress username and password text fields visible?
Here is the page source:
<form name="loginform" id="loginform" action="" method="post">
<label for="user_login">Username<br />
<input type="text" name="log" id="user_login" aria-describedby="login_error" class="input" value="" size="20" /></label>
<label for="user_pass">Password<br />
<input type="password" name="pwd" id="user_pass" aria-describedby="login_error" class="input" value="" size="20" /></label>
<script type="text/javascript">
if(jQuery.type(has_social_form) === "undefined"){
var has_social_form = false;
var socialLogins = null;
}
jQuery(document).ready(function(){
(function($) {
if(!has_social_form){
has_social_form = true;
var loginForm = $('#loginform,#registerform,#front-login-form');
socialLogins = $('<div class="newsociallogins" style="text-align: center;"><div style="clear:both;"></div></div>');
if(loginForm.find('input').length > 0)
loginForm.prepend("<h3 style='text-align:center;'>OR</h3>");
loginForm.prepend(socialLogins);
socialLogins = loginForm.find('.newsociallogins');
}
if(!window.fb_added){
socialLogins.prepend('<a href="" rel="nofollow"><div class="new-fb-btn new-fb-4 new-fb-default-anim"><div class="new-fb-4-1"><div class="new-fb-4-1-1">Login With Facebook</div></div></div></a><br />');
window.fb_added = true;
}
}(jQuery));
});
</script>
<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Log In" />
<input type="hidden" name="redirect_to" value="" />
<input type="hidden" name="testcookie" value="1" />
</form>
For normal user you can create another page and on that page you can set facebook login.
For admin, wp-admin is fine. So dont hide those input fields from wp-admin. login with facebook should be by another page.
This is the simple and time saving solution.
You can try something like that:
Explanation:
This simple code works by detecting a hash value in the URL and if it matches “
wpadmin
” then it will show the form, otherwise, keep it hidden (hidden by default using CSSdisplay:none
).Normal link – will show facebook only:
Link with hash – will show facebook and standard form:
jsFiddle