Naourass Derouichi
Naourass Derouichi

Reputation: 793

Wordpress child theme - Remove main theme Javascript file

In main theme functions.php I have :

wp_enqueue_script( 'template', get_template_directory_uri() . '/js/template.js', array('jquery'), '', true );

In child theme functions.php I've added :

add_action( 'wp_enqueue_scripts', 'remove_main_script' );
    function remove_main_script()
    {
        wp_dequeue_script('template');
    } 

The file template.js is still loaded. How can I remove it?

Upvotes: 0

Views: 435

Answers (1)

rnevius
rnevius

Reputation: 27092

You should add a priority to add_action() (10 is the default), to ensure that the parent styles and scripts are registered before you deregister them via your child theme:

add_action( 'wp_enqueue_scripts', 'remove_main_script', 20 );
function remove_main_script()
{
    wp_dequeue_script('template');
} 

Upvotes: 1

Related Questions