I am customising a Wordpress admin area and so far so good with a number of add_filter and add_action calls in my theme's functions.php file.

But I'm a bit worried because all this code will be executed on all pages, not just the admin area.

I therefore went ahead with the below approach:

if (is_admin())

It works but is this the cleanest way of doing it?

1 Answer 1


The way you do it is fine.

Also have a look at how Tom McFarlins WordPress Plugin Boilerplate does it:

if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {    
     require_once( plugin_dir_path( __FILE__ ) . 'admin/class-plugin-name-admin.php' );
     add_action( 'plugins_loaded', array( 'Plugin_Name_Admin', 'get_instance' ) );    



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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