0

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!

3
  • 1
    It is strongly recommended to have a unique identifier in the URL, so WordPress can quickly identify what type of content is being requested. If you want Posts, Videos, and TV Series to all have the same URL structure, you're going to end up with a slow website, because WordPress will have to check Posts, then Videos, and then TV Series for the requested slug. It's better to have a unique and relevant slug representing your CPTs.
    – Caleb
    Commented Oct 25 at 20:01
  • If the ChatGPT code worked, it wouldn't have broken the links on he whole site. That's a 'not working' thing. Commented Oct 25 at 20:07
  • I understand that each post type should have a different url structure now. But at least I need to modify it to make it look better. how can I modify? Commented Oct 25 at 20:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.