CPT not entering jQuery ready state

First post, excuse me if my formation or way of question is wrong.

Problem: Only Custom Post Types are not entering jQuery “ready” state, while Pages and Posts can.

Scripts are tied to custom header.

function themeslug_header_hook( $name ) {
    if ( 'gmsa' == $name ) {
        add_action( 'wp_enqueue_scripts', 'themeslug_header_style' );
    }
}
add_action( 'get_header', 'themeslug_header_hook' );

function themeslug_header_style() {
    wp_enqueue_style( 'twentysixteen-gmsa-style', get_stylesheet_directory_uri() . '/style-gmsa.css' );
    wp_enqueue_script( 'custom_gmsa_script', get_stylesheet_directory_uri() . '/script-gmsa.js', array( 'jquery' ), '2017.04', true );
}

Certain pages and CPT are using a custom template uses that header.

get_header('gmsa');

This works so far for Page that uses that template (which in turn uses that header).

But for CPT that uses the same template, the jQuery is not entering the “ready” state.

// CPT enters this file

/* window.onload = function() {
    if (window.jQuery) {  
        // jQuery is loaded  
        alert("Yeah!");
    } else {
        // jQuery is not loaded
        alert("Doesn't Work");
    }
} */
// Able to detect jQ

jQuery(document).ready(function($) {

    // CPT does not enter "ready" state

    ...

})

JS-wise, I think those are working right, so that makes me think that maybe something in my WP logic is not working right? I need some fresh eyes to see if I’m doing anything wrong.

Read more here: CPT not entering jQuery ready state

Leave a Reply

Your email address will not be published. Required fields are marked *