• Resolved ggg377

    (@ggg377)


    Hi, I’ve encountered what seems to be a syntax error on my behalf. I would like to use this code in my functions.php:

    if ( is_single() ) {
    add_action('init','copy_script');
    
    function copy_script() {
        wp_enqueue_script( 'copy-script-js', get_template_directory_uri() . '/js/copy.js', false, null );
    }
    }

    However, the javascript doesn’t get loaded up anywhere. If I use it like this, it gets loaded properly, but for all pages:

    add_action('init','copy_script');
    
    function copy_script() {
        wp_enqueue_script( 'copy-script-js', get_template_directory_uri() . '/js/copy.js', false, null );
    }

    I’m thinking this is a syntax issue. I want the script to be loaded up only on single pages. I would be glad if anyone could help me with this.

    ggg377

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting is_single to work in functions.php’ is closed to new replies.