Answer the question
In order to leave comments, you need to log in
How to connect scripts and styles separately on different WordPress pages?
Good morning everyone (◠‿◠)
In the project:
- 2 pages of categories for entries (News, Projects)
- WooCommerce online store
Separate styles and scripts are connected for each template because it is necessary
But the error is that the scripts and styles applied to the pages of categories of posts and the posts themselves,
are displayed on the pages of the store. (⊙▂⊙)
How can I fix this? ¯\_(o_O)_/¯
// ================================= СТРАНИЦЫ НОВОСТИ И ПРОЕКТЫ
if ( is_archive() || is_single() ) {
//if ( is_archive(array('24', '25')) || is_single() ) {
//if ( is_page_template(array('archive.php', 'single-news.php')) ) {
//if ( is_archive() || is_single() || ! is_woocommerce() || ! is_cart() || ! is_checkout() || ! is_account_page() ) {
//подключаем стиль в header
wp_enqueue_style('bkm-archive-css', get_theme_file_uri('css/news-project.min.css'));
//подключаем скрипт в подвале
wp_enqueue_script('bkm-archive-js', get_theme_file_uri('js/news-project.min.js'), array(), '', true);
}
// ================================= СТРАНИЦЫ WOOCOMMERCE
if ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ) {
//if ( ! is_single() || ! is_archive() || is_woocommerce() || is_cart() || is_checkout() || is_account_page() ) {
//подключаем стиль в header
wp_enqueue_style('bkm-woocommerce-css', get_theme_file_uri('css/shop.min.css'));
//подключаем скрипт в подвале
wp_enqueue_script('bkm-woocommerce-js', get_theme_file_uri('js/shop.min.js'), array(), '', true);
wp_enqueue_script('bkm-woocommerce-js', get_theme_file_uri('js/add-to-cart.min.js'), array(), '', true);
}
Answer the question
In order to leave comments, you need to log in
It's easiest to check post_type to apply styles for a specific post type. This condition will work for both archive and single pages.
if ( get_post_type() === 'post' ) {
# code...
}
if ( is_category( [ 'news', 'projects' ] ) || ( is_singular( 'post' ) && has_category( [ 'news', 'projects' ] ) ) ) {
# code...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question