0

I've tried using is_page() to pass the URL to but the page I am trying to enqueue my script on is "races/community/add" and isn't a single slug like "about-us". Is it possible to do this with is_page() or should I be approaching this in another way?

add_action( 'wp_enqueue_scripts', 'enqueue_date_picker_styles_and_scripts', 101);
function enqueue_date_picker_styles_and_scripts() {
    if ( is_page('races/community/add') ) {
        wp_enqueue_style('bootstrap-datepicker-css', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.standalone.css');
        wp_enqueue_script('bootstrap-datepicker-js', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js', array('jquery'),'1.8.0', true);
    }
}
  • Nothing is jumping out at me as wrong, but yes, you should be able to pass in a path like you are to is_page(). They specifically added support for that a long while back. – tmdesigned Apr 27 at 11:19
  • It's very odd that you've included a full URL path to a page there as the parameter, is_page expects the slug of a post of type page, not a URL path – Tom J Nowell Apr 27 at 12:29
0

is_page() accepts only one optional parameter $page which should be (int|string|array) representing Page ID, title, slug, or array of such.

On a standard WP installation your code should look like this.

add_action( 'wp_enqueue_scripts', 'enqueue_date_picker_styles_and_scripts', 101);
function enqueue_date_picker_styles_and_scripts() {
    if ( is_page('page-slug-here') ) {   // Replace page-slug-here with slug of page at races/community/add
        wp_enqueue_style('bootstrap-datepicker-css', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.standalone.css');
        wp_enqueue_script('bootstrap-datepicker-js', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js', array('jquery'),'1.8.0', true);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.