我目前正在使用 Wordpress 网络,当用户在移动设备上看到它时,我想为页面使用不同的模板。例如,我有一个名为 Proyects 的页面,它使用模板 gallery.php,但如果有人在移动设备中看到它,则同一页面 Proyects 使用模板 gallery_mobile.php。我不知道你是把它放在模板(即page.php)还是functions.php 中。
提前致谢!
要检查移动使用wp_is_mobile
,执行重定向,请挂钩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' );