普通而言,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自定义字段,很多插件也应用了这一性能。 自定义字段是一个十分...
header_image() header_image() 函数是 WordPress 自定顶部图像的规范接口函数,该函数能够主动判别后盾设置...
wordpress头部的代码十分多,包括WordPress版本,前后文、第一篇文章、主页meta信息等各种冗余代码,这些对...
wordpress操作数据库用一个全局变量$wpdb来进行各种操作,应用的时分先在函数申明global $wpdb,而后调用它...
博客吧转载了零号相册的Wordpress博客自带嵌套回复教程。 自带嵌套性能工作原理: wordpress嵌套回复的工作...
在以前的代码中,咱们仅仅应用add_shortcode函数来把短代码注册到wordpress中,在文章页应用the_content来显...