Whento use 'init' and when to use a function in functions.php?
-
Let’s say I want to disable users from viewing the dashboard.
I can add the following to
functions.php
:function hide_dashboard_init() { if ( is_admin() && !current_user_can( 'manage_options' ) ) { wp_redirect( home_url() ); exit; } } add_action( 'init', 'hide_dashboard_init' );
But why not just add a regular function to
functions.php
? Something like that:function hide_dashboard() {
if ( is_admin() && !current_user_can( ‘manage_options’ ) ) {
wp_redirect( home_url() );
}
}
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Whento use 'init' and when to use a function in functions.php?’ is closed to new replies.