Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WP – How to add a script to a specific page Reply To: WP – How to add a script to a specific page

#182157
Senff
Participant

No, that won’t work. As stated before, the script needs to be loaded when it’s a custom POST.

if ( is_page( 'ENTER-SLUG-HERE' ) ) { will only work if it’s a PAGE. What might work is IS_SINGULAR.


@taxicss
can you try this for fun?

// add google maps
    function load_google_script() {
        wp_register_script( 'googleapi', "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false");
        wp_register_script( 'googlemaps', get_template_directory_uri() . '/js/googlemaps.js', array(), '1.0.0', true );

    if(is_singular('YOURPOSTTYPE')) {
        wp_enqueue_script( 'googleapi' );
        wp_enqueue_script( 'googlemaps' );
    }
}
add_action( 'wp_enqueue_scripts', 'load_google_script' );

Not tested but give it a try. If it doesn’t work I’ll have to check it at home later today.