Are there any action like ‘init_frontend’

I’ve found init and init_admin. Are there any action that executes just in the frontend?
Thanks.

Related posts

Leave a Reply

4 comments

  1. You can combine add_action() and an is_admin() check:

    ! is_admin() and add_action( 'init', 'my_custom_callback' );
    

    Now the callback function will run on front-end only.

  2. Late to the party, but found the other answers not quite as clear.

    There is no init-like hook that is front-end only.

    admin_init only runs in the dashboard.

    init runs on both the front-end as well as the dashboard.

    So, combining the built-in WordPress function is_admin(), and the init hook, you can construct a function that allows you to do front-end only things:

    add_action( 'init', 'my_init_frontend_only_function' );
    
    function my_init_frontend_only_function() {
        // exit function if not on front-end
        if ( is_admin() ) {
            return;
        }
    
        // remaining code will only run on the front end....
        // do stuff here....
    }