I'm adding an action witht he following line:

add_action( 'admin_init', 'fb_init_scripts');

And my function looks like this:

  function fb_init_scripts() {
    //Only use these scripts in admin interface
    if (is_admin() ) {

In this instance, is it pointless to use is_admin() to controll if I'm in admin panel, since I'm running this function in admin_init ?


Yep, pointless.

admin_init only fires in admin area (and couple more files related to AJAX functionality) so additional is_admin() check is not necessary.

It often comes up in examples for hooks that fire both on front-end and admin area.


As Rarst said it's redundant. The ajax interface happens to be in the admin area for reasons related to authentication, and WP considers it to be part of the admin area -- including when it technically isn't.

A good "trick", that said, is to wrap applicable add_action() calls in an if block:

if ( is_admin() ) {
  add_action('admin_init', 'foo');

Doing so avoids polluting the $wp_filter global on the front end.

Better yet, create a separate file with admin-related code, and only include it in the admin area (or when needed, using the 'load-$pagehook' action). You can see an example of how this is done here:


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.