What is the condition to check if we are in admin or frontend?

Take a look at the is_admin() conditional tag:

function wpse106895_dummy_func() {
    if ( ! is_admin() ) {
        // do your thing
    }
}
add_action( 'some-hook', 'wpse106895_dummy_func' );

is_admin() returns true, if the URL being accessed is in the dashboard / wp-admin. Hence it’s negation (via the not operator) is true when in the frontend.

Update, see comments below:

function wpse106895_dummy_func() {
    // do your thing
}
if ( ! is_admin() ) add_action( 'some-hook', 'wpse106895_dummy_func' );

will save you overhead.

Leave a Comment