• Resolved UserDG

    (@tenkepadu)


    Hi, I’m trying to embed some custom js and css files. I put the custom js files in assets->js->third folder and load the js via functions.php in the child folder. I also tried in the parent theme folder, but none of them successfully load those custom files.

    Error: <strong>net::ERR_ABORTED</strong>

    Here’s my enqueue scripts

    wp_enqueue_script('custom-js', $dir .'/third/custom-js.js', array( 'jquery' ), $theme_version, true );
    wp_enqueue_script('custom-js-1', $dir .'/third/custom-js-1.js', array( 'jquery' ), $theme_version, true );

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author oceanwp

    (@oceanwp)

    Hello, in what function do you try to call your scripts? And what represents “$dir”?

    Thread Starter UserDG

    (@tenkepadu)

    I tried in child theme, but it’s not working. I also tried in parent theme, and still failed to load custom files. As I checked $dir is the path directory of files, I saw the same variable in the parent theme – function. So I copied it, and changed only the file name and stored the custom js files in assets->js->third

    Theme Author oceanwp

    (@oceanwp)

    Hi, ok, add this function in the functions.php file of your child theme:

    function prefix_custom_scripts() {
    	// Dynamically get version number of the parent stylesheet (lets browsers re-cache your stylesheet when you update your theme)
    	$theme   = wp_get_theme( 'OceanWP' );
    	$version = $theme->get( 'Version' );
    
    	wp_enqueue_script('custom-js', get_stylesheet_directory_uri() . '/js/custom-js.js', array( 'jquery' ), $version, true );
    	wp_enqueue_script('custom-js-1', get_stylesheet_directory_uri() . '/js/custom-js-1.js', array( 'jquery' ), $version, true );
    	
    }
    add_action( 'wp_enqueue_scripts', 'prefix_custom_scripts' );

    And add your custom scripts in a “js” folder in your child theme.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Embedded custom JS and CSS files issue’ is closed to new replies.