custom post type without category in slug
-
hi
I am using wck custom post type with custom post type permalinks so that I can have a custom post type for my articles.Until a few months ago the code below worked for removing the rewrite slug “article” from the links to my article pages. I don’t want the category in the link
Recently my system broke (appears to be a conflict with elementor that I am using on other pages. Elementor is not on article pages) and now while the links work – I can not add a target link to the code and when I am logged in I get a 404 error.Would anyone be able to help me work the code so that I don’t need to have the slug in the custom post type. I know that is not the way it usually works but my workaround was successful until now and perhaps someone has another work around.
thanks/** functions for removing article from the url */ function na_remove_slug( $post_link, $post, $leavename ) { if ( 'events' != $post->post_type || 'publish' != $post->post_status ) { return $post_link; } $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); return $post_link; } add_filter( 'post_type_link', 'na_remove_slug', 10, 3 ); function na_parse_request( $query ) { if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) { return; } if ( ! empty( $query->query['name'] ) ) { $query->set( 'post_type', array( 'post', 'article', 'source', 'page' ) ); } } add_action( 'pre_get_posts', 'na_parse_request' );
The page I need help with: [log in to see the link]
- The topic ‘custom post type without category in slug’ is closed to new replies.