2

I have avada theme, and I created child theme, how to add my custom js file in child theme.

I tried using this video tutorial, but without success https://www.youtube.com/watch?v=4xbvhXj72kU

Can you help me!

3 Answers 3

10

Here is best way to include custom js in child theme:

function my_scripts_method() {
wp_enqueue_script(
    'custom-script',
    get_stylesheet_directory_uri() . '/js/custom_script.js',
    array( 'jquery' )
 );
}

add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
Sign up to request clarification or add additional context in comments.

Comments

1

You can use the wp_enqueue_script() function.

documentation: https://developer.wordpress.org/reference/functions/wp_enqueue_script/

This function allows you to load scripts at any given time.

Comments

1

Create a folder in child theme and upload your JS file to that folder.

You can include a js file using

wp_enqueue_script()

or you can use

<script src="<?php echo get_stylesheet_directory_uri(); ?>/js/filename.js"  type="text/javascript"></script>

add the above code in theme header.php or footer.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.