2016-06-06 38 views

回答

2

這取決於您如何在頁面中設置

我認爲最好的方式來實現你真正想要的(需求)是使用PHP與條件規則:基於移動檢測

1)在有條件的模板。這樣你就可以避免同時加載2

你可以使用wp_is_mobile()條件WordPress的功能用於此目的:

<?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)在自定義簡碼與條件:

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)。

參考:

您也可以制定一個更精確的腳本來檢測平板電腦和手機,然後把它作爲一個條件爲不同的設備類型。

+0

我認爲應該提到的是,雖然這個答案中的一般方法是正確的,但'wp_is_mobile()'是一個近乎無用的函數。它不應該成爲WordPress目前形式的一部分。 –