I have this small bit of code which does exactly what I need. But I want to limit its use to one Custom Post Type (CPT) only.
add_filter('sanitize_title', 'my_custome_slug');
function my_custome_slug($title) {
return str_replace('-', '', $title);
}
I've tried the following code with no luck:
function my_custome_slug($title){
global $post;
if ( $post->post_type == 'customposttype') {
return str_replace('*', '-', $title);
}
}
add_filter('sanitize_title', 'my_custome_slug');
Any help is appreciated.
EDIT:
Sorry i was not clear in my post.
Wordpress is taking "Post Titles" and change them to "post-titles" in urls when we first enter the title in any new posts. My original question was , for a specific custom post type, i need to remove "-" in urls of the posts. So they will be "posttitles"
I thought the problem was using "sanitize_title" because every other example i found for custom post specific content loading in Admin panel works. But once i use sanitize_title in those examples, the result would simply make a blank url under the title field.
The first code i've shared is doing this already. I've tried to limit it's function to a specific custom posttype but it simply didnt work.
I need this feature and i saw its already possible. I just need to limit it to a specific custom post type. This is rather a backend problem (due to some internal structre) and not a frontend problem. Otherwise i would have tried it with htacess. So our main target is wordpress publish page on admin panel.
sanitize_title
is used a lot. This could be tricky, where do you want this applied? In what context? Save? Display? What?