如果UserAgent是iPhone,请动态更改url或WordPress主题 [英] Dynamically change url or WordPress theme if UserAgent is iPhone

查看:183
本文介绍了如果UserAgent是iPhone,请动态更改url或WordPress主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有办法吗?



我的网站是 http ://kennethreitz.com 。它由顶部Wordpress上的一些中等PHP驱动。



我的选项是检测用户是否使用iphone,如果他们是



告诉wordpress加载我写的不同的主题。
b)如果这是不可能的,在子域(i.kennethreitz.com)上使用不同主题的同一数据库操作不同的wordpress安装。


$



任何想法?

解决方案

http:// www .nathanrice.net / blog / serve-ie6-visitors-the-default-wordpress-theme / 演示了如何使用模板过滤器动态更改WordPress主题但可以是移动用户代理):

  add_filter('template','serve_default_to_iesix'); 
add_filter('option_template','serve_default_to_iesix');
add_filter('option_stylesheet','serve_default_to_iesix');

function serve_default_to_iesix($ theme){
if(strpos($ _ SERVER ['HTTP_USER_AGENT'],'MSIE 6')!== false)
$ theme ='default ';
return $ theme;
}


Is there any way to do this?

My website is http://kennethreitz.com. Its driven by some moderate PHP on top Wordpress.

My options are to detect if the user is using an iphone, and if they are either

a) tell wordpress to load a different "theme" that i have written. b) if this isn't possible, have a different wordpress installation on a subdomain (i.kennethreitz.com) that operates out of the same database, that uses a different theme.

I'd rather be able to do A for SEO reasons.

Any ideas?

解决方案

http://www.nathanrice.net/blog/serve-ie6-visitors-the-default-wordpress-theme/ demonstrates how to use template filter to dynamically change the WordPress theme (in this case IE6, but it could be for a mobile user agent):

add_filter('template', 'serve_default_to_iesix');
add_filter('option_template', 'serve_default_to_iesix');
add_filter('option_stylesheet', 'serve_default_to_iesix');

function serve_default_to_iesix($theme) {
    if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false)
        $theme = 'default';
    return $theme;
}

这篇关于如果UserAgent是iPhone,请动态更改url或WordPress主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆