移动设备的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!
我目前正在使用Wordpress网页,我想在用户看到时为页面使用不同的模板 它在移动设备上。 例如,我有一个名为Proyects的页面,它使用模板gallery.php,但是如果有人在移动设备中看到它,那么Proyects会使用模板gallery_mobile.php。 我不知道你是否把它放在模板中(即page.php)或者在functions.php中。 p>
提前致谢! p> DIV>
答
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' );