Move custom.js (or other theme script) into child theme

You may want to make alterations to a script like assets/js/custom.js or assets/js/theme.js, We can do that by adding this code into your child theme’s functions.php, so the theme will be updated easily.

// Add this function inside theme-js on the hook available there

add_action( 'spyropress_head', 'load_general_js_child', 12 );


// Function to de-register custom.js and re-register it in the child theme

function load_general_js_child() {


    // De-register loading in parent theme

    wp_deregister_script( 'theme-custom' );


    // register it to load with stylesheet_directory e.g. child theme root folder

    wp_register_script( 'theme-custom', get_stylesheet_directory_uri() . '/custom.js', false, '5.0.7', true );

    wp_enqueue_script( 'theme-custom' );


view rawfunctions.php hosted with ❤ by GitHub


Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Powered by Zendesk