• I need this JS to be loaded in the header, but no matter what I do, it’s still loaded at the bottom of the page.

    Here’s the set up of theme-functions.php:

    function ct_register_cssjs() {
      wp_register_script('gmaps', 'https://maps.google.com/maps/api/js?sensor=false', '', '1.0', false);
      wp_register_script('marker', get_template_directory_uri() . '/js/markerwithlabel.js', 'gmaps', '1.0', true);
    //other scripts cut for brevity
    }
    
    add_action('wp_enqueue_scripts', 'ct_register_cssjs');
    
    function ct_init_scripts() {
      wp_enqueue_script('gmaps');
      wp_enqueue_script('marker');
    //more scripts..
    }
    add_action('wp_enqueue_scripts', 'ct_init_scripts');

    I need, but can’t get the gmaps script to be placed in the <head>
    I’ve tried using blank space instead of false for $in_footer variable, but this hasn’t worked either.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Give this a try:
    wp_register_script('gmaps', 'https://maps.google.com/maps/api/js?sensor=false', '', '1.0');

    If that doesn’t work it might help to provide a link to the site and know what theme you are trying to use. You could also try switching to a WordPress default theme and see if your code works there. Also might try disabling any other plugins to make sure they are not causing an issue with what you are trying to do.

    Thread Starter keligijus

    (@keligijus)

    Thanks a lot AJ Mallory!

    Tried your version too, as false is the default, but no luck here.

    The problem was with a MapifyPro plugin. It also uses the same script and somehow forces it to be placed in footer.

    I’ve written to their support and hopefully they’ll be able to help me out.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘javascript won't load in header’ is closed to new replies.