WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to write code before user can enter username and password. So, I have code written just after the following line in wp-login.php page:

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'login';

The above line is somewhere # 372.

My line:

if ($action == 'login') {
   // My code

When done like this, script run before even username and pwd box comes. I am thinking of adding hook etc so that I do not need to modify wp-login.php page.

Any idea?

share|improve this question
I see wp_login and login_form but not sure about these. I prefer my code execute before user are present with login form. – Satya Prakash Oct 14 '13 at 9:47
You might want to take a look at this : How can I do customizations on login, registration and password recovery forms? – ialocin Oct 14 '13 at 10:15

If you don't care about the actual action you can use login_init action like this:

add_action( 'login_init', 'wpse8170_login_init' );
function wpse8170_login_init() {
    // do your stuff here

But if you want to handle only special actions, then you need to hook into login_form_{action} action, like this:

add_action( 'login_form_login', 'wpse8170_login_form_login' );
function wpse8170_login_form_login() {
    // do your login stuff here

Or like this:

add_action( 'login_form_register', 'wpse8170_login_form_register' );
function wpse8170_login_form_register() {
    // do your register stuff here

If you need to add some CSS or JS to your login page, then you need to use login_enqueue_scripts action:

add_action( 'login_enqueue_scripts', 'wpse8170_login_enqueue_scripts' );
function wpse8170_login_enqueue_scripts() {
    wp_enqueue_script( ... );
    wp_enqueue_style( ... );
share|improve this answer
Actually, these actions restricts something and leave something. I know if I could paste code then that would be helpful. My code was checking something in URL if it was there then page comes nicely (usual login page) but in these scenarios, it looks css or something does not comes. So, form comes at the top right corner. – Satya Prakash Oct 14 '13 at 13:22
I have udpated my answer and added login_enqueue_scripts action hook. Check it out! – Eugene Manuilov Oct 14 '13 at 13:32
Thank you, Eugene. I think it won't work. Voted up for your best effort. I have PHP after that line I have mentioned and above 3 hooks you have given did not work as expected so, possibly I need to live with wp-login.php file change. In the PHP just below that line, I check for cookie and url parameter, if that neither match then I exit. That is Security related stuff. – Satya Prakash Oct 15 '13 at 12:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.