Posted by: atom, 2010 01.04
John Resig tweeted the following:
Trying to get periods in Wordpress permalinks to work, but failing. How can I force WP to allow: http://example.com/foo.bar/
I was curious so I watched replies to him. There were many deeply misguided answers, my favorite being:
I’m not sure, but it seems like it might likely be a server configuration issue.
There was a reference to this: http://firsttube.com/read/hacking-wordpress-day-two/, but hacking the core is a pretty poor solution, and will be overwritten the next time you upgrade.
The periods get dropped by sanitize_title_with_dashes, and there is no clean way to hook into it and fix the problem, so you can just use remove_filter to drop it, and replace it with a very similar function that allows for periods:
remove_filter('sanitize_title', 'sanitize_title_with_dashes');
add_filter('sanitize_title', 'sanitize_title_with_dashes_allow_periods');
function sanitize_title_with_dashes_allow_periods($title){
// same as sanitize_title_with_dashes minus the line replacing periods,
// and an alteration to the final catch all regex to allow periods
// please note, might be dangerous for some reason? i don't rightly know.
$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);
$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);
}
$title = strtolower($title);
$title = preg_replace('/&.+?;/', '', $title); // kill entities
//$title = str_replace('.', '-', $title);
$title = preg_replace('/[^\.%a-z0-9 _-]/', '', $title); // allow for periods
$title = preg_replace('/\s+/', '-', $title);
$title = preg_replace('|-+|', '-', $title);
$title = trim($title, '-');
return $title;
}
Please note that this could be dangerous, they might be removing periods for a good reason
December 22nd, 2009 at 3:23 am
It says a validation error occured…
n i jus followed ur link…it didnt appear in my home page…
February 15th, 2010 at 4:00 am
Sorry, no longer works, at least for me either.
Maybe they were about to add you to the team …