L
L
Leonid2022-01-12 11:10:29
WordPress
Leonid, 2022-01-12 11:10:29

How to properly use Bower inside a WordPress theme?

So, there is a custom theme for a WordPress site, where you need to use different JS/jQuery scripts/libraries on different pages.

Well, for example, slick-carousel will be used on certain types of pages ( https://github.com/kenwheeler/slick/ )
How can I connect it - so that it is in the context of using the minimization and caching plugin?
those. in theory, it is necessary through wp_enqueue_script () and wp_enqueue_style () with checking the post type, and where this slider will be inserted as a block through Visual Composer, for example - somehow you need to determine its presence and only then load it?

instead of like this in the page template file:

<link rel="stylesheet" href="/wp-content/themes/mytheme/bower_components/slick-carousel/slick/slick.css">
<link rel="stylesheet" href="/wp-content/themes/mytheme/bower_components/slick-carousel/slick/slick-theme.css">
<script src="/wp-content/themes/mytheme/bower_components/slick-carousel/slick/slick.min.js" type="text/javascript"></script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kulnev, 2022-01-12
@alexanderkulnyow

type yes, check what page and load appropriate script
if ( is_singular( 'post_type') ) {
wp_enqueue_script( ... );
}
https://wp-kama.ru/function/wp_enqueue_script

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question