dongwu3596 2013-05-27 17:34
浏览 25
已采纳

移动设备的Wordpress重定向页面模板

I'm currently working on a Wordpress web and i want to use a different template for a page when a user sees it on a mobile device. For example I have a page called Proyects that uses the template gallery.php but if somebody sees it in a mobile device the same page Proyects use the template gallery_mobile.php. I don't know if is something you put it in the template (ie page.php) or in the functions.php.

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • douzhi9939 2013-05-27 17:49
    关注

    To check for mobile use wp_is_mobile, to perform a redirect, hook into template_redirect:

    function so16778006_mobile_redirect()
    {
        if( is_page( 'proyects' ) && wp_is_mobile() )
        {
            include( get_template_directory() . '/gallery_mobile.php' );
            exit();
        }
    }
    add_action( 'template_redirect', 'so16778006_mobile_redirect' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?