スクリプトを特定のページ テンプレートにエンキューしようとしていますが、if ステートメントのスクリプトが読み込まれていないようです。is_page バージョンを試してみましたが、同じことを行います。誰かが私が間違っているところを指摘できれば、とても感謝しています。
function di_load_javascript()
{
// Deregister the included library
wp_deregister_script( 'jquery' );
// Register the library again from Google's CDN
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js', array(), null, false );
wp_register_script( 'jquery-masonry', get_template_directory_uri() . '/js/jquery.masonry.min.js', array( 'jquery' ), null, true );
wp_register_script( 'blog-scripts', get_template_directory_uri() . '/js/blog.js', array( 'jquery' ), null, true );
wp_register_script( 'home-scripts', get_template_directory_uri() . '/js/home.js', array( 'jquery' ), null, true );
// Enqueue the scripts for all pages
wp_enqueue_script( 'jquery' );
// Enqueue the scripts for Home
if ( is_front_page() ) {
wp_enqueue_script('home-scripts');
};
// Enqueue the scripts for Blog (is_page_template fails for some reason)
//if ( is_page(array(2,'blog','Blog')) ) {
if ( is_page_template('templates/blog.php') ) {
wp_enqueue_script('jquery-masonry');
wp_enqueue_script('blog-scripts');
};
}
add_action( 'wp_enqueue_scripts', 'di_load_javascript' );
奇妙なのは、スクリプトが is_front_page を介してホームページに読み込まれることです。私は非常に混乱しています :(