I’ve found init and init_admin. Are there any action that executes just in the frontend?
Thanks.
Leave a Reply
You must be logged in to post a comment.
I’ve found init and init_admin. Are there any action that executes just in the frontend?
Thanks.
You must be logged in to post a comment.
You can combine
add_action()
and anis_admin()
check:Now the callback function will run on front-end only.
‘template_redirect’ is the most useful one.
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:You can use
wp_loaded
action for this.https://codex.wordpress.org/Plugin_API/Action_Reference/wp_loaded