让你的wordpress博客可以根据来路自动跳转到中英文版本
如果你需要用wordperss同时建立不同语言版本的博客网站,想让国内的朋友访问中文版,而让国外的朋友访问英文版,或是其他语言版本的话,这里介绍你一种最简单的修改方法,就可以实现。使用PHP判断浏览器语言,然后作相应跳转,这么做比使用IP库响应更快,当然,不是相当的精确,但能满足大致的需要了,因为会使用中文浏览器的用户,无论国内还是国外,应该是懂中文的,相应的,使用英文版浏览器的用户也是如此。
打开wordpress根目录下的Index.php文件,然后修改成下面的代码即可:
<?php $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4); //只取前4位,这样只判断最优先的语言。如果取前5位,可能出现en,zh的情况,影响判断。 if (preg_match("/zh-c/i", $lang)){ /** * Front to the WordPress application. This file doesn't do anything, but loads * wp-blog-header.php which does and tells WordPress to load the theme. * * @package WordPress */ /** * Tells WordPress to load the WordPress theme and output it. * * @var bool */ define('WP_USE_THEMES', true); /** Loads the WordPress Environment and Template */ require('./wp-blog-header.php'); }else{ header("HTTP/1.1 301 Moved Permanently"); header ("Location:http://en.wheatv.com"); } ?>
你可以尝试将你的浏览器语言设置成英文的,然后再来访问www.wheatv.com 。
在网上还有JS判断操作系统语言的方法,但是我不是很推荐,如果这样,你的网站默认首页将会是一个仅有JS跳转判断的文件,这对SEO恐怕不是很好。
七月 5th, 2010 in Posted in 玩转WP 1 Comment »









这个很强大哟。。。
[回复]