• Hi,
    I am trying to add javascript helloworld to my template file. I have added the following code to my header.php file:

    ‘<?php
    function my_script_load() {
    wp_register_script(‘sitescript’, get_bloginfo(‘template_directory’).’/js/webcam.js’, array(), false);
    wp_enqueue_script(‘sitescript’);
    }
    ?>
    <?php
    if( is_page(‘webcam’)) {
    add_action(‘init’, ‘my_script_load’);
    }
    ?>

    <?php wp_head(); ?>’

    where webcam is my template file name for webcam.php.

    The javascript inside of the webcam.js file is:
    ‘<script type=”text/javascript”>
    alert(‘Hello, World!’);
    </script>’

    I can’t tell way it’s not loading. Any help would be much appreciated. Thanks, Margaret

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mames40

    (@mames40)

    changed ‘if( is_page(‘webcam’)) {‘ to
    ‘if( is_page_template( ‘webcam.php’ )){ ‘ but still doesn’t load :(.

    Please help. Margaret

    Thread Starter mames40

    (@mames40)

    I saw an implementation using functions.php but I don’t understand how the javascript gets loaded into a particular template using that approach. :(.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do I add my hello word javascript to my template file’ is closed to new replies.