温馨提示:网站使用自适应技术,手机与电脑显示界面不同,电脑界面显示效果更佳。

做了个小站,积累一些技术,分享一些原创
    体会生活,记录一些小随笔,闲说心得

让新版wordpress支持中文网址url的代码修改

原创:张荣国

因为wordpress原版本来源于国外,所以,一般默认是以UTF8字符集,而更好的中文支持的字符集为GBK。所以,如果你一开始做站时未将字符集进行修改或想更好兼容而使用utf8字符集的话,那么你只能修改代码一并兼容来更好的使用。

例如,我们在中文版编辑文章时,如果字符集默认UTF8没修改,固定链接为使用:%postname%(也就是文章名),那么,你发布中文标题的文章后,它的固定链接就会是中文网址url了。比如我这篇,或许就会是:

https://zhangrongguo.com/archives/让新版wordpress支持中文网址url的代码修改

那么上面这样的网址,打开查看,就会是404找不到页面了。

原因就是刚才说到的字符集问题:提交过来的URL中文字符,那么它的字符集是GBK ,而URL根据这GBK的字符串查找,是UTF8字符集,当然找不到了。

所以,也有了一些wordpress插件可来满足补这个问题。

但其实,我们也只需修改一下wordpress的一个文件的两行代码,使之兼容两个字符集,也就解决了。无需装多余的插件。

首先,要说一下,网上也是有这样的修改方法的,可是多数为给旧版的wordpress修改,比如4.8版本等,但其实,现在新版的wordpress的源代码以有不同,所以,修改也就不同了。好了,直接看修改:

隐藏内容,回复可见(无需登录注册)    “回复本文”后“刷新页面”查看隐藏内容!

点击数:855

你可能也喜欢下面相关文章:

5 讨论

  1. Cupar to edinburgh airport transfer说道:

    I have been exploring for a bit for any high-quality articles or weblog
    posts on this kind of house . Exploring in Yahoo I finally stumbled upon this web site.
    Reading this info So i am glad to convey that I’ve a
    very excellent uncanny feeling I discovered exactly what I
    needed. I most indisputably will make sure to do not
    omit this website and give it a glance on a relentless basis.

  2. mtproto proxy说道:

    hey there and thank you for your information – I’ve certainly picked up
    something new from right here. I did however expertise several technical issues using this web site, as I experienced to reload the site lots of times previous to I could get it to load correctly.
    I had been wondering if your web hosting is OK? Not that I am complaining, but slow loading instances times will
    very frequently affect your placement in google and can damage your high-quality score if advertising and marketing with Adwords.
    Well I’m adding this RSS to my email and can look out for much more of your respective intriguing content.

    Make sure you update this again very soon.

  3. free slot machine games说道:

    SuperPlay303 Agen Slot Online Game Joker Gaming Dan Joker123 MAXWIN Terbaik Sebagai agen joker123 slot
    on-line terpercaya dan enteng jackpot, link joker123 login apk menggunakan server paling baik dan sesungguhnya sudah teruji bakal kualitas tersebut.
    Biasanya para recreation slot online terbaru ini udah punyai lisensi formal kelas internasional dan sudah
    pasti bakal menjamin kelancaran para pemain.

  4. 99资源说道:

    看看

  5. 3333说道:

    1111111

回复 3333 取消回复

必填项已用*标注