Got a question. Does anybody know how to change the url a duplicate title creates?

If I create two posts, both named test, the addresses would be example.com/test and example.com/test-2

I would like it to be named test and test2, without the - sign. It looks nicer, since the -2, means "duh, you did a duplicate" but if it's called for example manning2 , "ahh, Manning nr 2"

There will be a lot of those, since I'm using the title as users name, and many have the same names ;)


For details please see this answer : Remove Dash/Hyphen From Wordpress CustomPosttype Permalink

In your functions.php :

function no_dashes($title) {
    return str_replace('-', '', $title);
add_filter('sanitize_title', 'no_dashes' , 9999);

For particular type of post :

function no_dashes( $slug, $post_ID, $post_status, $post_type ) {

    if( $post_type == "page" ) {
        $slug = str_replace( '-', '', $slug);
    return $slug;
add_filter( "wp_unique_post_slug", "no_dashes", 10, 4 );
| improve this answer | |
  • Well, that actually only removed so it didn't read the -, when creating a new post, it was still named example-2 instead of example2. I tried the first one.. – Jerry Sep 9 '18 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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