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' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试