我想为我的网站移动版提供不同的静态主页.它不是一个真正的额外移动版本,但它是响应.
我现在将全屏图像滑块设置为静态主页.由于网站的重新构建,这可以扩展到屏幕大小,但在移动设备(如iPhone)上看起来不太好.所以我有这个其他主页模板,我想在移动设备上浏览网站时使用.
这可以通过任何插件完成,还是应该通过编码完成?我不想使用主题切换器或类似的东西,我只想为移动设备设置不同的静态页面.
谁知道怎么做?
dig*_*ggy 10
您可以使用wp_is_mobile检查移动设备,并在检测到移动设备时挂钩template_redirect以加载其他模板:
function so16165211_mobile_home_redirect(){
if( wp_is_mobile() && is_front_page() ){
include( get_template_directory() . '/home-mobile.php' );
exit;
}
}
add_action( 'template_redirect', 'so16165211_mobile_home_redirect' );
Run Code Online (Sandbox Code Playgroud)
我将Mobile-Detect包含在自己文件夹中的主题中,并在header.php的开头添加此代码:
if( is_front_page() ){
include_once('mobile-detect/Mobile_Detect.php');
$detect = new Mobile_Detect();
if ( $detect->isMobile() || $detect->isTablet() ) {
$redirect_url = 'http://example.com/mobile_home';
header('Location: ' . $redirect_url ); // Redirect the user
}
}
Run Code Online (Sandbox Code Playgroud)
您可以根据需要自定义此解决方案.我已经将它用于几个项目以获得类似的解决方案.
| 归档时间: |
|
| 查看次数: |
22647 次 |
| 最近记录: |