Not Preventing Duplicate URLs
-
The plugin does put up a notification about there being a duplicate URL but the admin saves it anyway. I think this is a pretty big bug. Are there plans to resolve this or do you have any instructions on how I’m able to resolve this?
-
Hi @fencer04,
To be honest, this was done by design. I applied it as a “soft” alert without changing any user-entered permalinks, so the users can decide how to proceed.
The main reason behind it is that I receive repeated support requests where users wanted to use the plugin to override native taxonomy archive URLs with custom pages built in Elementor or Beaver Builder.
Your point makes absolute sense, so I will add a new toggle field “Force unique permalinks” in the plugin settings, so the plugin can automatically handle this (if user decides to).
In the meantime (before new version is released), please use this code snippet as a temp. patch:
function pm_force_unique_permalink( $new_uri, $post_id, $post = '' ) {
global $permalink_manager_uris;
// Determine post ID
if ( is_a( $post, 'WP_Post' ) ) {
$post_id = $post->ID;
} elseif ( ! is_numeric( $post_id ) ) {
return $new_uri;
}
// Copy URIs and exclude current element
$uris = $permalink_manager_uris;
unset( $uris[ $post_id ] );
$uris = array_flip( $uris );
// Prepare base + extension
if ( ! preg_match( '/^(.+?)(?:-([\d]+))?(\.[^\.]+$|$)/', $new_uri, $parts ) ) {
return $new_uri; // fallback if regex fails
}
$base = $parts[1];
$index = empty( $parts[2] ) ? 1 : (int) $parts[2];
$extension = $parts[3];
$unique_uri = $new_uri;
// Increment suffix until URI is unique
while ( isset( $uris[ $unique_uri ] ) ) {
$index++;
$unique_uri = "{$base}-{$index}{$extension}";
}
return $unique_uri;
}
add_filter( 'permalink_manager_pre_update_post_uri', 'pm_force_unique_permalink', 999, 3 );
add_filter( 'permalink_manager_filter_default_post_uri', 'pm_force_unique_permalink', 999, 3 );Thank you, that is amazing support. I’ve tested this and it appears to be working on my end. When the update is done I will remove this code.
I am happy to help π
Once the new version is released, please make sure that “Force unique custom permalinks” option is enabled in the plugin settings:

We have the new setting setup on our site and it is working. The only issue is that we are running WPML and are unable to have the same permalink for different lanaguges. For example:
http://www.url.com/page
http://www.url.com/es/page
With the setting turned on it is forcing this instead:http://www.url.com/page
http://www.url.com/es/page-2Can you let me know what I need to do to make sure we are able to go back to the previous structure. Each time we edit one of the translations it updates the URL and creates a redirect.
Hi @fencer04,
The function that forces the unique permalinks ignores the language code, so it will automatically append “-2” to the slug for URLs in the different languages. I will try to adjust this in the next plugin’s release, but for now I would recommend to turn “Force unique custom permalinks” off.
The quickest way to adjust the previous URLs is to use bulk editor – if you use “-2” as search term – you should be able to find all the affected custom permalinks:

Could I turn if off and adjust the function that you provided me earlier in the meantime? If so do you know what change would need to be made?
Yes, I will try to implement the patch to the dev version in the next 1-2 hours. I will get back to you immediately after I finish and double-check it.
Sorry for the inconvenience!
Could you try to manually overwrite the contents of:
wp-content/plugins/permalink-manager/includes/core/permalink-manager-helper-functions.phpfile with this code?
https://pastebin.com/raw/GPeZhMJd
The new patched function now also should check the language code to prevent the “false positives” when the URLs includes duplicated slug but different language code, so the URL as a whole is unique.
-
This reply was modified 2 months, 2 weeks ago by
Maciej Bis.
Thank you, I will check on this between today and tomorrow and report back.
This did not work. When I removed the “-2” from the permalink it still added it back when I saved the page.
Technically, the “-2” can be appended also if you have auto-update mode enabled + slugs mode uses the default settings (“Use WordPress slugs”).
Could you send me the screenshot with:
- Permastructure settings (“Tools -> Permalink Manager -> Permastructures”)
- General settings (“Tools -> Permalink Manager -> Settings -> General settings”)
If possible, please also record a short video showing all the steps, so I can reproduce them on my test server.
-
This reply was modified 2 months, 2 weeks ago by
Maciej Bis.
Here are the screenshots that you asked for. One note is that the permalink structures are the same for English and Spanish.
All that happened was saving the page and the -2 was added. If I edit the permalink removing the -2 it gets added back when I click update.
Thanks, everything is set-up correctly. Have you tried to check if it works for more than one specific custom permalink or for more of them?
Troubleshooting this further can be difficult, because I am not able to reproduce this bug any longer. After I identified it and applied a fix, the Permalink_Manager_Helper_Functions::force_unique_uri() function seem to work as expected.
I have tested it in several configurations, including both WPML and Polylang – but I think I might missing something – could you possibly record a screencast or send me extra screenshots showing step-by-step how exactly you edit the permalink?
I did some more testing on my end and I believe it’s working now. I’m not sure what was wrong with my testing the first couple of times. Is this going to be implemented in a release soon or should I replace this file in my other environments?
Perfect, I am glad that it works correctly now.
The patch will be added in the next plugin’s release.
-
This reply was modified 2 months, 2 weeks ago by
You must be logged in to reply to this topic.