<script type="text/javascript">
jQuery(document).ready(function( $ ){
$("#user_login").val('User ID');
$("#user_login").on("focus", function(){this.value='';});
$("#user_pass").val('Password');
$("#user_pass").on("focus", function(){this.value='';});
});
</script>
This will set the value of the User ID field to “User ID” and the Password field to “Password”, as well as set an event handler that will clear the fields when the field gets the focus. The problem, though, is that the password field is of type password, so the placeholder is going to be concealed.
]]>add_action( 'wp_enqueue_scripts', 'add_my_script' );
function add_my_script() {
wp_enqueue_script(
'script_new', // name your script so that you can attach other scripts and de-register, etc.
get_template_directory_uri() . '/assets/js/script_new.js', // this is the location of your script file
array('jquery') // this array lists the scripts upon which your script depends
);
}
This causes no changes for me.
I also tried it with script_new.js
in my functions.php
Did I add the jQuery correctly?
There will also be a src attribute for your JS file. Be sure the URL leads to your actual file.
If that all checks out, check your browser’s JS console for additional clues.
]]>
Checking the console might have revealed the error.
I changed the code to:
jQuery(document).ready(function( $ ){
$("#user_login").val('User ID');
$("#user_login").on("focus", function(){this.value='';});
$("#user_pass").val('Password');
$("#user_pass").on("focus", function(){this.value='';});
});
now it is showing the placeholder for User Name.
For the password the placeholder is censored.
Is there any possibility to make the placeholder visible but censor the user input?
Thank you
jQuery(document).ready(function( $ ){
$("#user_login").val('User ID');
$("#user_login").on("focus", function(){this.value='';});
$("#user_pass").attr('type', 'text');
$("#user_pass").val('Password');
$("#user_pass").on("focus", function(){this.value='';document.getElementById('user_pass').type = 'password';});
});
]]>