hero image

Overriding a script from the parent theme

Home Forums Knowledge Base Overriding a script from the parent theme

Forums Knowledge Base Overriding a script from the parent theme

PLEASE NOTE A RECENT CHANGE:
The forum is read-only. Please submit any support request here.

This topic contains 0 replies, has 1 voice, and was last updated by  Tesla 4 years, 10 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts

  • Tesla
    Member
    Member
    #25032

    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: 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

    <?php
    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');
    ?>
    

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

Viewing 1 post (of 1 total)

Overriding a script from the parent theme

Home Forums Knowledge Base Overriding a script from the parent theme

[i]
[i]
[i]
[i]