I created the following scripts and added them the functions.php file within my WordPress them:
add_action('wp_enqueue_scripts', 'scripts_styles');
function scripts_styles(){
if(is_page_template('Disclosures.php')){
wp_enqueue_script('jquery', get_template_directory_uri().'/js/jquery.validate.js', array(), GOVPRESS_VERSION, false );
wp_enqueue_script('jquery', get_template_directory_uri().'/js/jquery.min.js', array(), GOVPRESS_VERSION, false );
wp_enqueue_script('bootstrap', get_template_directory_uri().'/js/bootstrap.min.js', array(), GOVPRESS_VERSION, false );
wp_enqueue_script('handlebars', get_template_directory_uri().'/js/handlebars.min.js', array(), GOVPRESS_VERSION, false );
wp_enqueue_script('addrows', get_template_directory_uri().'/js/addrows.js', array(), GOVPRESS_VERSION, false );
}
}
function wpse_enqueue_page_template_styles() {
if ( is_page_template( 'Disclosures.php' ) ) {
wp_enqueue_style( 'bootstrapthemecss', get_template_directory_uri() . '/css/bootstrap-theme.min.css', array(), GOVPRESS_VERSION, false );
wp_enqueue_style( 'bootstrapcss', get_template_directory_uri() . '/css/bootstrap.min.css', array(), GOVPRESS_VERSION, false );
wp_enqueue_style( 'maincss', get_template_directory_uri() . '/css/main.css', array(), GOVPRESS_VERSION, false );
}
}
add_action( 'wp_enqueue_scripts', 'wpse_enqueue_page_template_styles' );
However, they are not recognized by my custom template.
In other words, I tested my page with these scripts and stylesheets and they work very well.
I was able to validate form fields and display the results in the styles that was specified.
Yet, they are not validating the same form fields and page is not being styled.
What am I missing?
Just an FYI, the name of the theme is govpress.
Thanks for your help in advance.
You seem to be enqueuing two scripts with the same name: jquery
. However, jquery
is already present in WordPress and you might notice wp_enqueue_script()
description says: does NOT override. This means whenever you are trying to enqueue a script with the same name as a previously enqueued script... nothing happens.
If you're not happy with the existing version of jquery
embedded in WP, you need to deregister it and register the new one, with this exact name: jquery
. The name is very important, as a lot of WP scripts depend on jquery
. If you replace it, they'll depend on your version instead of the included one. Make sure you enqueue a version of jquery
regardless of your templates logic (if you removed the default one).
You should specify jquery
as a dependency in the dependencies array of each script that depends on jquery
.
If none of your scripts and styles load, you might want to debug your script checking if is_page_template('Disclosures.php')
returns true in the page you're testing this on. A simple die('this just happened...')
will do for testing purposes.