We are migrating a site to WordPress from another platform. An issue came up with the URLs--some are uppercase, some lowercase. I allowed uppercase using this solution: How can I make Capital letter ( upper-case ) permalinks?

However, I am running into some problems as follows:

  1. Some parent pages must be uppercase, while some are lowercase: site.com/page/other-page vs. site.com/Page/another-page

  2. WordPress does not allow duplicate page slugs, even though they are Uppercase vs. lowercase (since WP goes by the assumption that all slugs and urls will be lowercase). Of course, browsers and Google, unlike WordPress, do treat them as separate urls, resulting in 404s if you mistype the url capitalization or click on a link that has different capitalization.

  3. A possible tack was to make some pages into posts and use a category as a "parent page”. This turned out to be impractical, as the post permalinks must be category/%page_id%-%postname% to comply with Google News requirements and match the old site. Therefore all post slugs must be category/%page_id%-%postname%, which does not match the old site on the particular pages that need the uppercase vs. lowercase scenario—they just need to be /parent-page/%postname%

  4. I would prefer not to do 301 redirects per-page—just too much. I would also prefer that the urls stay the same as the old site as much as possible. Making a whole custom post type just for this situation seems unnecessary. Is it possible to override WordPress’s adding on of -2 to duplicate slugs or else have a 301 redirect to the lowercase version of the parent page slug just on the pages I need? I cannot use the Redirection plugin as it conflicts with other plugins we must use on the site. Are there any other suggestions?


1 Answer 1


You can try this. Paste this below code in your function.php theme file. This is working for me.

// Remove existing filter
remove_filter( 'sanitize_title', 'sanitize_title_with_dashes' );

// Function to maintain capitalization in slugs
function maintain_capitalization_slug($title, $raw_title, $context) {
// Apply only when saving slugs
if ($context === 'save') {
// Preserve capitalization and replace special characters with hyphens
$title = preg_replace('/[^a-zA-Z0-9]+/', '-', $raw_title); // Replace non-alphanumeric characters with hyphens
$title = trim($title, '-'); // Trim leading/trailing hyphens
return $title;

// Apply the custom function to 'sanitize_title'
add_filter('sanitize_title', 'maintain_capitalization_slug', 10, 3);
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 1 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.