Removing Unnecessary Slug
-
Hi everyone,
I am using a theme which utilizes different post types such as regular “posts”, “videos” and “tv series”. I can add a post at “posts” tab, I can add a video(this is a kind of post) at “videos” tab, and the same goes for “tv series” tab too.
I am experiencing an annoying url problem. My permalinks are custom structured: /%category%/%postname%/
This works perfectly fine when I post a normal post via “posts” tab. However, when I post a custom post type (in videos or tv series tab) the url goes something like: mydomain..com/title/example-movie-name and when I post an episode, the url goes: mydomain..com/episodes-title/example-series-episode-3/. /title/ is always there for “video” posts, and /episodes-title/ is alawys there for “tv series” posts. They are so irritating.I tried using custom code via code snippet plugin, thanks to chatgpt, to remove those unnecessary slugs (/title/ and /episodes-title/) from the url. It actually worked but it also broke all the links and the whole website so I had to undo it. I also tried inserting that code in functions.php but the results were the same. Also, my mod_rewrite is on.
There are more than 2000 “tv series posts(episodes)” and 100 “video posts”, so even if there is a way to do this with a plugin, manually one by one, I guess I couldn’t do it as it’d take soo long. I need to remove those unnecessary slugs in a shorter way.
At this point, I am not even sure if I really need to remove that slug. I just think it is unnecessary and in terms of seo, it’s better if I remove it. The cleaner the url is, the better experience for the user, right? I am not sure even if I manage to edit the urls, would it create indexing problems?
Here is the custom code chatgpt gave me: (video_skrn and episodes_skrn are the names for my custom post types)
function custom_post_type_slug($args, $post_type) {
if ($post_type === ‘video_skrn’) { // Replace ‘videos’ with your post type slug
$args[‘rewrite’] = array(‘slug’ => ‘/’); // Blank slug removes it completely
}
if ($post_type === ‘episodes_skrn’) { // Replace with your post type slug
$args[‘rewrite’] = array(‘slug’ => ‘/’);
}
return $args;
}
add_filter(‘register_post_type_args’, ‘custom_post_type_slug’, 10, 2);I appreciate any help, thanks!
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.