admin管理员组文章数量:1415139
I would like to use underscore in my permalinks instead of hyphen.
Current permalink:
www.example/2013/01/hello-this-is-a-test-post/
Desired permalink
www.example/2013/01/hello_this_is_a_test_post/
I have tried some solutions mentioned here in stacexchange. But they were not working.
I would like to use underscore in my permalinks instead of hyphen.
Current permalink:
www.example/2013/01/hello-this-is-a-test-post/
Desired permalink
www.example/2013/01/hello_this_is_a_test_post/
I have tried some solutions mentioned here in stacexchange. But they were not working.
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Jan 5, 2013 at 16:12 PrivateUserPrivateUser 3,46910 gold badges54 silver badges85 bronze badges 7 | Show 2 more comments3 Answers
Reset to default 1it can be done easily without any codes or plugin just go to pages dashboard, click Quick Edit" which url you want to change. Now add underscore. Update and done
Toscho advised me like this.
Google treats - as word separator, but not _. You will hurt yourself. :)
He was 100% true. Here is an article that explains it. So I dropped the idea.
But if you still looking for a solution here is the answer.
Answered by this stackoverflow user
Hunt down the following file:
wp-includes/formatting.php
Jump down to the
sanitize_title_with_dashes
function. You'll find this section of code inside:$title = strtolower($title); $title = preg_replace('/&.+?;/', '', $title); // kill entities $title = str_replace('.', '-', $title); $title = preg_replace('/[^%a-z0-9 _-]/', '', $title); $title = preg_replace('/\s+/', '-', $title); $title = preg_replace('|-+|', '-', $title); $title = trim($title, '-');
Swap out all of the dashes/hyphens (
-
) for underscores (_
) like so:$title = strtolower($title); $title = preg_replace('/&.+?;/', '', $title); // kill entities $title = str_replace('.', '_', $title); $title = preg_replace('/[^%a-z0-9 _-]/', '', $title); $title = preg_replace('/\s+/', '_', $title); $title = preg_replace('|-+|', '_', $title); $title = trim($title, '_');
Note that any posts you've created before this change, and rely on the
%postname%
permalink structure tag, will be broken.In that case you'll need to go back and republish those post so the dashes are swapped out for the underscores. Or just write yourself a little SQL to replace them.
I initially did this but with every update to Wordpress I'd have to make the manual change again, so I made this plugin in case it helps anyone: http://wordpress/plugins/underscores-in-permalinks/
本文标签: functionsConvert hyphen to underscore in permalinks
版权声明:本文标题:functions - Convert hyphen to underscore in permalinks 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745212061a2647947.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
-
as word separator, but not_
. You will hurt yourself. :) – fuxia ♦ Commented Jan 5, 2013 at 16:24