Support » Fixing WordPress » Custom Plugin – Getting Code to run on WP_ADMIN Login

  • Hey,

    I am just starting to write plugins for wordpress and I’m trying to write one that will execute a piece of code whenever someone logins to the admin dashboard.

    Specifically I am trying to run a script that will generate a cookie so I can exclude all site admins from showing up on Google Analytics.

    Google says that I have to add a piece of code inside the <body> tag how can I do that with a plugin? what hooks would I need?


Viewing 4 replies - 1 through 4 (of 4 total)
  • See the action reference.

    I’d guess you’d need to hook onto wp_login …

    ok cool I’ll give it a shot

    so im trying to create a cookie and im having some trouble

    here is my code so far

    function set_cookie()
    setcookie(“RandomName”, “RandomValue”, time()+2592000,”/”,”localhost”);


    all I want is for the cookie to be created or update when an admin logs in (or the dashboard load)via wp_admin

    what am I doing wrong here?

    Try adding an action onto wp_validate_auth_cookie, which should be when a user has logged in under valid credentials. Grab the current user ID at this point to determine role, then go ahead and do whatever you want to from there.

    See wp-includes/pluggable.php, from lines 506 – 548, and you’ll see there’s quite a few hooks there .. the above suggested hook is on line 545.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Plugin – Getting Code to run on WP_ADMIN Login’ is closed to new replies.