Last active
August 29, 2015 13:57
-
-
Save wuliupo/9701055 to your computer and use it in GitHub Desktop.
wordpress language switch, no refesh, cookie remember;多语言切换,不刷新页面,cookie 记住当前语言
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// /wp-content/themes/****/functions.php | |
add_filter( 'body_class', 'lang_body_classes' ); | |
function lang_body_classes( $classes ) { | |
if($_GET['lang']=='en' || $_COOKIE['lang']=='en'){ | |
$classes[] = 'en'; | |
@setcookie('lang', 'en'); | |
} | |
return $classes; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- /wp-content/themes/****/header.php --> | |
<div class="lang"><span data-lang="cn">中文</span> <span data-lang="en">English</span></div> | |
<script type="text/javascript"> | |
jQuery('.lang span').click(function(){ | |
var lang=jQuery(this).attr('data-lang'); | |
document.cookie='lang='+lang; | |
jQuery('body').removeClass('cn en').addClass(lang); | |
}); | |
</script> | |
<style type="text/css"> | |
.en, body.en .cn{display: none;} | |
body.en, body.en .en{display: block;} | |
</style> |
Post Content, 正文内容应该包含两套标签:
Any HTML tag (span, p, or div),
<tag class="cn">中文内容</tag>
<tag class="en">Chinese Content</tag>
remove all filters 移除对应的 HTML 标签过滤函数, esc_attr, esc_url, esc_attr_e, esc_html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Menu Setting (Admin Console, /wp-admin/nav-menus.php):