• Resolved hifumi

    (@hifumi)


    I’m currently using this code:

    function enqueue_myscript() {
            wp_enqueue_script('jquery-javascript', true );
            wp_enqueue_script('javascript', true);
            wp_enqueue_script('ijavas', get_template_directory_uri() . '/js/', array( 'jquery' ), '', true );
            wp_enqueue_script('javas2', get_template_directory_uri() . '/js/', array( 'jquery' ), '', true );  
    }
    if(is_page('index.php')){
    add_action('wp_enqueue_scripts', 'enqueue_myscript');
    }

    I can’t seem get this to work. I know it’s not index.php, so how can I point it accordingly to only the index page? I am not using a template page either.

    The script is being called for every single page, but only the index.php contains the required code that uses the script.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    is_page takes as a parameter “Page ID, title, slug, or array of such to check against.” Thus, “index.php” won’t work.

    Also, index.php is executed for *every page* on a wordpress site. If you’re targeting the home page for your site, use is_front_page or is_home.

    Thread Starter hifumi

    (@hifumi)

    Thank you, this stopped the error popping-up on other pages that doesn’t require this JavaScript.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How do I load several JavaScripts for a specific page?’ is closed to new replies.