wordpress在postname中支持大写字母的方法
一般而言,WordPress本身会对英语用户的体验进行优化,例如默认模板的分隔符永远都是“|”,因为英文单词以空格空开,要区分两个单词不可能用“-”,因此“|”是最好的选择。同样,为了让URL更符合浏览器解析和用户的识别,wordpress默认会将标题中的英文大写字母lower到小写。 然而对于中文网站来说,这或许不是一件很好的是,如果要在URL中使用中文,那么使用大写也是常有的,这里提供一种取消wordpress自动降级字母大写的方法。 $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); } //$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,'-'); return $title;} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |