Removing Slug Gives 404 in Child Posts
-
Hi
I am trying to remove the slug in my custom post type following the instructions here: https://michaelbox.net/2020/06/slugless-post-type-permalinks/
I have the following two codes I got from the website:
function cptui_demo_remove_slug_from_permalink_string( $post_link, $post ) { if ( 'publish' !== $post->post_status ) { return $post_link; } if ( 'hub' === $post->post_type ) { $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); } return $post_link; } add_filter( 'post_type_link', 'cptui_demo_remove_slug_from_permalink_string', 10, 2 ); function cptui_demo_add_post_type_to_query( $query ) { if ( is_admin() || ! $query->is_main_query() ) { return; } if ( empty( $query->query['name'] ) ) { return; } $query->set( 'post_type', [ 'post', 'page', 'hub', ] ); } add_action( 'pre_get_posts', 'cptui_demo_add_post_type_to_query' );
After implementing the code I saved the permalink structure in settings. But I am still getting the 404 error.
I believe this is because this post is a child to another post and the same is reflected in the URL. Meaning
domain.com/hosting is the parent and has no 404 error here. But domain.com/hosting/wp-engine-review is the child and it gets a 404 error.
What can I do so that the child page doesn’t get any 404 error.
The page I need help with: [log in to see the link]
- The topic ‘Removing Slug Gives 404 in Child Posts’ is closed to new replies.