add_action functioning

Asked

Viewed 35 times

0

I’m running some tests on the wp_head() of a Wordpress theme, the same uses a hooks scheme with the add_action, i believe I understand how it works, the first parameter is the main function wp_head and the second is the name of the function where I am calling example do_active_header.

What happens is that by default this theme imports many unnecessary files which makes it very slow to load my page. My doubt and if I can make one add_action more than once for the same function, as here for example:

function do_activate_header() {
    /**
     * Fires before the Site Activation page is loaded.
     *
     * Fires on the {@see 'wp_head'} action.
     *
     * @since 3.0.0
     */
    do_action( 'activate_wp_head' );
}
add_action( 'wp_head', 'do_activate_header' );
add_action( 'wp_head_teste', 'do_activate_header' );

I want to do this way to understand exactly which files I need to import and which ones I can remove

1 answer

1


Yes, you can do so... you can also use remove_action to remove the action from the default theme

remove the action that adds the scripts

# exemplo
function theme_name_scripts() {
  wp_enqueue_script( '$handle', '$src', array( 'jquery' ), false, false );
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

# removendo action acima 
remove_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.