Forums

Why is my function not working? (2 posts)

  1. egr102
    Member
    Posted 3 months ago #

    I'm trying to load up two JS files to just my template file 'contact.php'. The function below isn't working (its located in my functions.php file):

    function google_map_script() {
    	   // register your script location, dependencies and version
    	   wp_register_script('maps_script',
    	   	   'http://maps.googleapis.com/maps/api/js?sensor=false',
    	       array('jquery')
    	       );
    
    	   wp_register_script('gmap_script',
    	       get_template_directory_uri() . '/js/gmap.js',
    	       array('jquery')
    	       );
    
    	   // enqueue the script
    	   wp_enqueue_script('maps_script', 'gmap_script');
    	}
    
    	if ( is_page_template( 'contact.php' ) ) add_action('init', 'google_map_script');

    I'd appreciate any pointers or help at all :)

  2. Try add_action('wp_enqueue_scripts', 'my_scripts_method'); instead of add_action( 'init' ... and remove that wp_enqueue() that you already have.

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

Reply

You must log in to post.

About this Topic