如何为仅移动设备加载特定的Slider Revolution? [英] How to load a specific Slider Revolution for mobile-only?
问题描述
I know that there is a responsive feature for revolution-slider, but unfortunately it still loads all the mobile assets on desktop and vice versa, adding time to the page-load.
因此,我希望有2个不同的滑块,每个设备一个.
So I'd prefer to have 2 distinct sliders, one per device.
什么是最好的解决方案?
What's the best solution for this?
推荐答案
这取决于您如何设置 revslider .
It depends on how you are setting your revslider in your pages.
我认为,实现您真正想要的(需求)的最佳方法是使用带有条件规则的php:
I think that the best way to achieve what you really want (need) is using php with conditional rules:
1)在您的模板中有条件地基于移动检测.这样,您将避免同时加载2个revslider 时间.
1) In your templates with conditional based on mobile detection. This way you will avoid loading 2 revslider at the same time.
为此,您可以使用wp_is_mobile()
有条件的wordpress功能:
You could use wp_is_mobile()
conditional wordpress function for this purpose:
<?php
if ( !wp_is_mobile() ) {
echo do_shortcode('[rev_slider alias="my_desktop_slider"]');
}
else
{
// mobile devices
echo do_shortcode('[rev_slider alias="my_mobile_slider"]');
}
?>
2)在具有该条件的自定义简码中:
2) In a custom shortcode with that conditional:
if( !function_exists('rev_slider_detection') ) {
function rev_slider_detection( $atts ) {
extract(shortcode_atts(array(
'alias' => '' // the alias name of your desktop rev-slider
), $atts));
$output = '[rev_slider alias="';
if ( !wp_is_mobile() ) {
// For desktop only
$output .= $alias . '"]';
} else {
// For mobile only
$output .= $alias . '_mob"]';
}
return $output;
// or (because untested)
// return do_shortcode('" . $output . "');
}
add_shortcode('my_rev', 'rev_slider_detection');
}
您将以这种方式使用它:[my_rev alias="my_revslider_alias_slug"]
,您将需要有2个rev滑块实例,第一个实例用于具有别名的台式机(例如home
),第二个实例用于具有相同别名的移动设备别名 +"_mob" (例如home_mob
).
You will use it this way: [my_rev alias="my_revslider_alias_slug"]
and you will need to have 2 instance of a rev slider, the first one for desktop with some alias name ( home
for example) and the second one for mobile with same alias name + "_mob" ( home_mob
for example).
参考:
- WP codex wp_is_mobile
- WP codex do_shortcode
- Shortcode Generator
您还可以精心设计更准确的脚本来检测平板电脑和手机,然后将其用作针对不同设备类型的条件.
You can also elaborate a more accurate script to detect tablets and phones, then use it as a conditional for different devices types.
这篇关于如何为仅移动设备加载特定的Slider Revolution?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!