欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

wordpress在postname中支持大寫(xiě)字母的方法

  發(fā)布時(shí)間:2014-02-26 14:52:40   作者:佚名   我要評(píng)論
本文主要介紹了wordpress在postname中支持大寫(xiě)字母的方法,wordpress默認(rèn)會(huì)將標(biāo)題中的英文大寫(xiě)字母lower到小寫(xiě),要在URL中使用中文,那么使用大寫(xiě)也是常有的,這里提供一種取消wordpress自動(dòng)降級(jí)字母大寫(xiě)的方法

一般而言,WordPress本身會(huì)對(duì)英語(yǔ)用戶的體驗(yàn)進(jìn)行優(yōu)化,例如默認(rèn)模板的分隔符永遠(yuǎn)都是“|”,因?yàn)橛⑽膯卧~以空格空開(kāi),要區(qū)分兩個(gè)單詞不可能用“-”,因此“|”是最好的選擇。同樣,為了讓URL更符合瀏覽器解析和用戶的識(shí)別,wordpress默認(rèn)會(huì)將標(biāo)題中的英文大寫(xiě)字母lower到小寫(xiě)。

然而對(duì)于中文網(wǎng)站來(lái)說(shuō),這或許不是一件很好的是,如果要在URL中使用中文,那么使用大寫(xiě)也是常有的,這里提供一種取消wordpress自動(dòng)降級(jí)字母大寫(xiě)的方法。

復(fù)制代碼
代碼如下:

remove_filter( 'sanitize_title', 'sanitize_title_with_dashes' );
add_filter( 'sanitize_title', 'use_capital_letter_in_slug' );
function use_capital_letter_in_slug($title) {
$title = strip_tags($title);
// Preserve escaped octets.
$title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
// Remove percent signs that are not part of an octet.
$title = str_replace('%', '', $title);
// Restore octets.
$title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);</p> <p> $title = remove_accents($title);
if (seems_utf8($title)) {
//if (function_exists('mb_strtolower')) {
// $title = mb_strtolower($title, 'UTF-8');
//}
$title = utf8_uri_encode($title, 200);
}</p> <p> //$title = strtolower($title);
$title = preg_replace('/&.+?;/', '', $title); // kill entities
$title = str_replace('.', '-', $title);
// Keep upper-case chars too!
$title = preg_replace('/[^%a-zA-Z0-9 _-]/', '', $title);
$title = preg_replace('/\s+/', '-', $title);
$title = preg_replace('|-+|', '-', $title);
$title = trim($title, '-');</p> <p> return $title;
}

將上面的代碼拷貝到你的主題文件functions.php中,它即可取消wordpress對(duì)postname的格式化,同樣,它也對(duì)分類(lèi)、標(biāo)簽等的別名起作用。

相關(guān)文章

最新評(píng)論