Question

Wordpress is changing "Post Titles" to "post-titles" when we first enter the title (Done with ajax ?). For a specific custom post type, i need to remove "-" in urls of the posts. So they will be "posttitles"

I’ve been doing it manually for a while but i believe i can force urls to remove "-" among them. This post type usually have 2 words titles and at most 3 words titles.

I understand its done through AJAX but i couldn’t separate the url rewrite code from the main batch (let alone devise a plugin that will alter it to my needs). Any idea or suggestion is welcome at this point.

Also this is rather a backend problem and not a frontend problem. Otherwise i would have tried it with htacess. So our main target is wordpress publish page on admin panel.

Thank you

Edit:

Ive still not figurred out how to do this to specific custom post type.

I took Aggelos Synadakis code below and changed it to this.

The closest i came is this code.

add_filter('post_type_link', 'portfolioPermalinks');
function portfolioPermalinks($post, $title) {
$post_id = $post->ID;
    if($post->post_type == 'customposttype'){
        $var1 = sanitize_title($title);
    $title = str_replace(' ', '', $var1);
    return $title;
    }

}

This code makes rest of the sites posts to have normal urls while "customposttype" url to be blank. So in a way, i did manage to effect a specific post type but not the way i wanted.

No correct solution

OTHER TIPS

In order to change the default slug structure, try the following code to your functions.php file:

function my_custome_slug($title) {
    return str_replace(' ', '', $title);
}
add_filter('sanitize_title', 'my_custome_slug');

In the same way, you can apply any other change you would like to the default slug format.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top