Created
July 17, 2014 08:30
-
-
Save JosefJezek/ea16852d30bb4663e3b6 to your computer and use it in GitHub Desktop.
Wordpress Periods / Dots in Title / Slug / URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Periods in Title | |
Version: 1.0 | |
Description: Allows periods to appear in post/category URIs | |
Author: Mark Jaquith | |
Plugin URI: http://txfx.net/code/wordpress/periods-in-titles/ | |
Author URI: http://txfx.net/ | |
*/ | |
remove_filter('sanitize_title', 'sanitize_title_with_dashes'); | |
function sanitize_title_with_dots_and_dashes($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, '-'); | |
$title = str_replace('-.-', '.', $title); | |
$title = str_replace('-.', '.', $title); | |
$title = str_replace('.-', '.', $title); | |
$title = preg_replace('|([^.])\.$|', '$1', $title); | |
$title = trim($title, '-'); // yes, again | |
return $title; | |
} | |
add_filter('sanitize_title', 'sanitize_title_with_dots_and_dashes'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, worked perfectly!