Thread Starter
chris
(@achensee)
I still want to know how I can enqueue the wp swiper frontend script and styles for certain template pages. I parsed the code and tried the following method, but this doesn’t work.
$wp_swiper_public = new WP_Swiper_Public('wp-swiper');
add_action('wp_enqueue_scripts', function() use ($wp_swiper_public) {
$wp_swiper_public->enqueue_frontend_assets();
});
Also i tried just simply
wp_enqueue_script('wpswiper-bundle-js');
wp_enqueue_style('wpswiper-bundle-css');
without success.
-
This reply was modified 1 month, 1 week ago by
chris.
-
This reply was modified 1 month, 1 week ago by
chris.
-
This reply was modified 1 month, 1 week ago by
chris.
-
This reply was modified 1 month, 1 week ago by
chris.
Thread Starter
chris
(@achensee)
Solved and provided without any guarantee. For anyone who disable the option ‘Always load Swiper JS bundle on every page.’ and need to enqueue the wp-swiper Front-End Scripts on custom templates:
// Swiper-JS Add Frontend Scripts and Styles
if (!function_exists('hf_load_swiper')) {
function hf_load_swiper() {
// Check if the class 'WP_Swiper_Public' exists
if (class_exists('WP_Swiper_Public')) {
$wp_swiper_public = new WP_Swiper_Public('wp-swiper', '1.0.0');
add_action('wp_enqueue_scripts', function () use ($wp_swiper_public) {
if ($wp_swiper_public instanceof WP_Swiper_Public) {
if ($wp_swiper_public instanceof WP_Swiper_Public) {
update_option('wp_swiper_options', ['enqueue_swiper' => 'on']); // set load swiper temporarily to on
$wp_swiper_public->enqueue_frontend_assets(true); // Enqueue Swiper Front End Assets
update_option('wp_swiper_options', ['enqueue_swiper' => '']); // reset load swiper
}
}
});
}
}
}