I have three templates I want to be able to use (Index Page, Main Template, and Default). I was able to add a "if/else" statement into a function to get the correct CSS file to load depending on which template was being used between two templates (Index and Default).
However, when I try to use "elseif" so I can add in another option for Main Template, it doesn't work. Instead the page that uses Main Template loads the Index Page CSS.
This is the code in question:
if ( is_page() && ! is_page_template( 'page-templates/index_page.php' ) ) {
wp_enqueue_style( 'authorLuncheon-layout-style1', get_template_directory_uri().'/layouts/index_page.css' );
} elseif ( is_page() && ! is_page_template( 'page-templates/main_template.php' ) ) {
wp_enqueue_style( 'authorLuncheon-layout-style2', get_template_directory_uri().'/layouts/main_template.css' );
} else {
wp_enqueue_style( 'authorLuncheon-layout-style3', get_template_directory_uri().'/layouts/content-sidebar.css' );
}
Here's the whole function:
function authorluncheon_scripts() {
wp_enqueue_style( 'authorluncheon-style', get_stylesheet_uri() );
if ( is_page() && ! is_page_template('page-templates/index_page.php' ) ) {
wp_enqueue_style( 'authorLuncheon-layout-style1', get_template_directory_uri().'/layouts/index_page.css' );
} elseif ( is_page() && ! is_page_template( 'page-templates/main_template.php' ) ) {
wp_enqueue_style( 'authorLuncheon-layout-style2', get_template_directory_uri().'/layouts/main_template.css' );
} else {
wp_enqueue_style( 'authorLuncheon-layout-style3', get_template_directory_uri().'/layouts/content-sidebar.css' );
}
wp_enqueue_script( 'authorluncheon-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
wp_enqueue_script( 'authorluncheon-skip-link-focus-fix', get_template_directory_uri().'/js/skip-link-focus-fix.js', array(), '20130115', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'authorluncheon_scripts' );