Yes, I am preparing one more solution.
Well, but both snippset do not to work correctly with my form plugin.
What form plugin do you use?
The new snippet is ready. The hook is triggered after:
- new post is added & custom permalink generated
- existing post is updated via WordPress admin dashboard
function pm_force_unique_permalinks($post_id, $new_uri, $old_uri) {
global $permalink_manager_uris;
while(empty($new_unique_permalink)) {
$duplicates = array_keys($permalink_manager_uris, $new_uri);
if(is_array($duplicates)) {
$duplicated_ids = array_flip($duplicates);
// Ignore this particular post
if(isset($duplicated_ids[$post_id])) {
unset($duplicated_ids[$post_id]);
}
// Count duplicates
$duplicates_count = count($duplicated_ids) + 1;
// Add numeral prefix to the URL
if($duplicates_count > 1) {
preg_match('/(.*)-([\d]{1,3})$/', $new_uri, $out);
if(!empty($out[2])) {
$new_uri = sprintf('%s-%d', $out[1], (int) $out[2] + 1);
} else {
$new_uri = preg_replace('/(.+?)(\.[^\.]+$|$)/', '$1-' . $duplicates_count . '$2', $new_uri);
}
} else {
$new_unique_permalink = $new_uri;
}
}
}
$permalink_manager_uris[$post_id] = $new_unique_permalink;
update_option('permalink-manager-uris', $permalink_manager_uris);
}
add_action('permalink_manager_updated_post_uri', 'pm_force_unique_permalinks', 10, 3);
add_action('permalink_manager_new_post_uri', 'pm_force_unique_permalinks', 10, 3);
Thx, seems to work, but doesn’t work with my front end form.
I will like to centralize “jetpack_subscription_form title” in my site, please help out.
sorry for posting unrelated topic on this thread. I could not find create new topic. thanks
Just to get my anwser to this
There is one particular reason why I made it like this. First of all, with my plugin you can edit the full permalink and not only the native slug (the native slug is always unique and cannot be assigned to more than one post/term). This feature is widely used as it allows to reuse the same slug when the full URL address is unique as a whole:
And why not have both? The system should only ad numbers to the slug when it’s necessary.