Detect front-end pages only in init hook
I'm trying to early exit a function within the "init" hook if it's not a front-end page. This is what I have so far, but it's definitely running on wp-json endpoints. Does anyone have a complete "early exit" clause that will ensure this is ONLY running on front-end pages?
add_action('init', 'test');
function test() {
if ( is_admin || wp_doing_ajax() ) {
return;
}
// Do stuff here
}
Topic plugin-development Wordpress
Category Web