[wp-hackers] Use a period in permalinks
Ryan Bilesky
rbilesky at gmail.com
Sat Oct 2 20:47:23 UTC 2010
If all you need is to allow periods, you can use this bit of code. I took
it from the advanced-permalinks plugin, this is how it does that, just add
it to your theme's functions.php
function sanitize_title_allow_period($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);
$title = remove_accents($title);
if (seems_utf8($title)) {
if (function_exists('mb_strtolower')) {
$title = mb_strtolower($title, 'UTF-8');
}
$title = utf8_uri_encode($title);
}
$title = strtolower($title);
$title = preg_replace('/&.+?;/', '', $title); // kill entities
$title = preg_replace('/[^%a-z0-9\. _-]/', '', $title);
$title = preg_replace('/\s+/', '-', $title);
$title = preg_replace('|-+|', '-', $title);
$title = trim($title, '-');
return $title;
}
remove_filter ('sanitize_title', 'sanitize_title_with_dashes');
add_filter ('sanitize_title', 'sanitize_title_allow_period', 10, 1);
On Fri, Oct 1, 2010 at 8:51 PM, WP Customizer <wpcustomizer at gmail.com>wrote:
> I am trying to use a . (period) in a permalink for a page, but it just
> changes to a - (dash). Is there anyway to get this to work with a period,
> I
> want to include a non-whole number as part of the permalink like
> mysite.com/hello-world-1.0.1 or mysite.com/1.1
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list