Skip to content

Instantly share code, notes, and snippets.

@chaushevic
chaushevic / allow-dots-in-wp-url.php
Last active October 4, 2018 14:33
Allow saving URL with dots in WordPress
<?php
// Remove and copy over default sanitize_title_with_dashes functionality and add dot as allowed character
remove_filter( "sanitize_title", "sanitize_title_with_dashes", 10 );
add_filter( "sanitize_title", function($title, $raw_title = "", $context = "display") {
$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);