I'm having issues enqueueing a script in the header. I'm working on a Wordpress site where the page content is loaded via AJAX. To do this I have to enqueue the script with the AJAX call. I do this using the following code:
function ajax_enqueue_scripts() {
$dir = plugins_url().'/product-types';
global $post;
if ( 'product' === $post->post_type ) {
wp_enqueue_script( 'ajax-products', $dir. '/js/ajax.js', __FILE__, array('jquery'), '1.2',false );
wp_localize_script( 'ajax-products', 'ajaxfunction', array('ajax_url' => admin_url( 'admin-ajax.php' )));
}
}
add_action( 'wp_enqueue_scripts', 'ajax_enqueue_scripts' );
The problem is that it keeps loading the JS file in the footer. Is there something I'm missing?