WordPress converts my post title to a permalink which is great, the only thing is that I want underscores instead of hyphens, is there a quick solution?
Leave a Reply
You must be logged in to post a comment.
WordPress converts my post title to a permalink which is great, the only thing is that I want underscores instead of hyphens, is there a quick solution?
You must be logged in to post a comment.
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:Swap out all of the dashes/hyphens (
-
) for underscores (_
) like so: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 wouldn’t do it mainly because of SEO’s issues.
Is there any specific reason for you to do it? Every solution I read here is about hacking wordpress core, and everytime you update your system you’re going to edit all these files again. (In fact, 2.8.6 was avaiable just yesterday. If you’re using and old version, you would need to change two times).
Look for function sanitize_title_with_dashes() in wp-includes/formatting.php
Change the calls to preg_replace there to use underscores instead of hypens.
I would not recommend changing core wordpress files, you will lose your work as soon as you upgrade your site. You can make a plugin, or put this in your theme’s functions.php file.