Wordpress 4.9.5

I am work on demo to check after login call some action or function, so that i prepare one plugin. Here is the code.

Plugin Name: Test Login
Plugin URI: http://wordpress.org/plugins/
Description: This is not just a plugin,
Version: 1.0

function your_function() {
    echo "123";
    echo "<script>alert('login')</script>";
add_action('wp_login', 'your_function');

But it is not working after successful login from this URL : http://localhost/test_wordpress/wp-login.php. It will redirect to dashboard and alert message was not display. Please help for that.

Thank you.


wp_login is fired in wp_signon after the user has successfully logged in.

That's after submitting the login form, so obviously you can't execute any JavaScript there. Of course you can still do something in PHP.

If you want to execute JavaScript after login, you need to find another hook.

  • 1
    Thank you, Which hook execute after successfully login except 'wp_login' – Rahul bhut Apr 5 '18 at 3:34
  • 1
    If you want to execute PHP after logging in, wp_login is fine. If you want to execute JavaScript in the admin area after logging in, you could look at the admin_head hook for example. – swissspidy Apr 5 '18 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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