Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Is it possible to have desktop/ mobile and tablet cache separately

$
0
0

Replies: 0

I build a custom theme to make homepage with different view depends on device.
This is th code I switch the template for frontpage:

add_filter( 'template_include', 'front_page_template', 99 );

function front_page_template( $template ) {

    if ( wp_is_mobile() && is_front_page() ) {
        $new_template = locate_template( array( 'page-home-mobile.php' ) );
        if ( '' != $new_template ) {
            return $new_template ;
        }
    }

    return $template;
}

It only works for desktop and mobile device.
Are there any other way to make a tablet cache?

I try to use filter to determine tablet device with “Mobile Detect” library.
Like:

add_filter( 'wp_is_mobile', 'custom_is_mobile', 101 );

function custom_is_mobile($is_mobile) {
    global $mobile_detect;

    if(!$mobile_detect->isMobile() && $mobile_detect->isTablet()){
        $is_mobile = false;
    }

    return $is_mobile ;
}

It seems like not work.
Do you hv any other suggestion for these? Thank you


Viewing all articles
Browse latest Browse all 59525

Trending Articles