广告
返回顶部
首页 > 资讯 > CMS >wordpress在postname中支持大写字母的方法
  • 663
分享到

wordpress在postname中支持大写字母的方法

大写字母 2022-06-12 02:06:35 663人浏览 八月长安
摘要

一般而言,WordPress本身会对英语用户的体验进行优化,例如默认模板的分隔符永远都是“|”,因为英文单词以空格空开,要区分两个单词不可能用“-”,因此“|&

一般而言,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的格式化,同样,它也对分类、标签等的别名起作用。

--结束END--

本文标题: wordpress在postname中支持大写字母的方法

本文链接: https://www.lsjlt.com/news/32093.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作