I read many Q&As here on SO...(and elsewhere but they don't count...lol)
I think I follow the rules of WP.org but still it does not load the scripts.
Scenario: Custom template for post in Php:
<?php
/*
* Template Name: YYY
* Description: Form for YYY donation.
* NO FOOTER
*/
get_header(); ?>
<div id="content-yyy">
theme functions.php
function donate_adding_scripts() {
wp_register_script('donateParsleyJs', get_template_directory_uri() . '/js/parsley.min.js', array('jquery'),'1.11.1');
wp_enqueue_script('donateParsleyJs');
wp_register_script('donateParsleyHeJs', get_template_directory_uri() . '/js/he.js');
wp_enqueue_script('donateParsleyHeJs');
wp_register_script('donateJs', get_template_directory_uri() . '/js/donateJs.js', array('jquery'),'1.11.1', true);
wp_enqueue_script('donateJs');
}
function donate_adding_styles() {
wp_register_script('donateStyle', get_template_directory_uri() . '/donateStyle.css');
wp_enqueue_script('donateStyle');
}
function loadDonateScripts() {
if (is_single()) {
global $post;
if($post->ID=="8436"){ // only for post Id = 8436
add_action( 'wp_enqueue_scripts', 'donate_adding_scripts' );
add_action( 'wp_enqueue_scripts', 'donate_adding_styles' );
}
}
}
add_action( 'wp_enqueue_scripts', 'loadDonateScripts');
As I am using a setLocal for parsleyjs I have
<script type="text/javascript">
window.ParsleyValidator.setLocale('he');
</script>
I have several issues:
- the addition to functions.php does not load the CSS
- the JS scripts only load if I add
$in_footer=true
to functions.php file andget_footer();
to the php template - All that said I wish to load these only for the specific custom post (ID=8436) hence
function loadDonateScripts()
I wish to have the scripts loaded(obviously...duh), preferably in the footer... Any ideas??