普通而言,WordPress自身会对英语用户的体验进行优化,例如默许模板的分隔符永远都是“|”,由于英文单词以空格空开,要区分两个单词不可能用“-”,因而“|”是最好的抉择。同样,为了让URL更合乎阅读器解析和用户的辨认,wordpress默许会将题目中的英文大写字母lower到小写。
但是关于中文网站来说,这或者不是一件很好的是,假如要在URL中应用中文,那么应用大写也是常有的,这里提供一种勾销wordpress主动降级字母大写的办法。
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对postname的格局化,同样,它也对分类、标签等的别名起作用。
以上就是安达网络工作室关于《wordpress在postname中支持大写字母的方法》的一些看法。更多内容请查看本栏目更多内容!
喜爱折腾修正Wordpress主题的冤家,一定遇到过这样的成绩,想在首页文章中显示缩略图,有插件能够完成,不过...
随着搜寻引擎大兴, 陈列在前的网站引入大量流量. 无论是搜寻页面的广告还是查进去的后果, 与搜寻者的指标婚...
此时假如上传一个不在预约义的平安扩大名列表,如.lrc,会报错: File type does not meet security guidel...
繁忙了n天,我的wordpress终于挂到了公网上,开端内侧,不过呈现了成绩,下面一切的链接,不论是本人博客中...
WordPress的文章、评论等很少数据都是寄存在数据库的,所以搭建wordpress网站的工夫,网站的空间不需求多大...
很多冤家刚建设博客的时分都是采纳国际优秀的博客零碎:Z-BLOG,用一段工夫当时很多人都想转移到wordpress,...