• Hello ,
    I am trying to enqueue script , So i created js with code
    alert("sometext");
    & added this in functions.php

    function virtue_scripts() {
    
    	wp_enqueue_script( 'testjava', get_template_directory_uri() . '/wp-content/themes/virtue/testjava.js', array(), '1.0.0', false );
    }
    
    add_action( 'wp_enqueue_scripts', 'virtue_scripts' );

    But its not working ,
    When i add it through headers.php , it works perfectly.
    Where am i going wrong?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Have you viewed source to see whether the right path is being used?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You’ll see something like:

    <script src="/wp-content/themes/virtue/wp-content/themes/virtue/testjava.js">

    By the way, aren’t you using a Child Theme?

    Thread Starter rdxcsgoid

    (@rdxcsgoid)

    Hello Andrew,
    thanks for the help !
    I couldnt find
    <script src="/wp-content/themes/virtue/wp-content/themes/virtue/testjava.js">
    in page source.
    and yea i am not using child theme.
    So what should i do now?
    Do i have to register the script? I have only created js file in my hosting panel .

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Try doing this instead in your Child Theme functions.php file:

    function virtue_child_scripts() {
    
    	wp_enqueue_script( 'testjava', get_stylesheetdirectory_uri() . 'testjava.js', array(), '1.0.0', false );
    }
    
    add_action( 'wp_enqueue_scripts', 'virtue_child_scripts' );

    Then link us your site

    Thread Starter rdxcsgoid

    (@rdxcsgoid)

    Hi ,
    i created the child theme & added functions.php & testjava.js in it ,
    I added this code

    <?php
    
    function virtuechild_scripts() {
    
    	wp_enqueue_script( 'testjava', get_stylesheetdirectory_uri() . 'testjava.js', array(), '1.0.0', false );
    }
    
    add_action( 'wp_enqueue_scripts', 'virtuechild_scripts' );

    But still not working.
    My website https://cardmart.tk

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you ask your hosting providers whether they’re caching your website?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘enqueue scripts’ is closed to new replies.