Overriding a script from the parent theme

Sometimes customization of a theme can’t be achieved only by editing the php files. In few cases you will need to make changes to the scripts too. In order achieve this you will need to deregister a script from the parent theme and use another in your child theme. Here is the example code that you need to paste in function.php from child theme:

function register_child_options(){
wp_deregister_script( 'options.js' );
wp_enqueue_script( 'options', get_stylesheet_directory_uri() . '/js/options.js', false,true );
add_action('wp_enqueue_scripts', 'register_child_options');

NOTE: the provided code is for demonstration purposes. You should adapt it to your own needs. In this example we will be overriding the options.js file

After this you will be able to use options.js script from your child theme folder.

Have more questions? Submit a request


Powered by Zendesk