Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Step 1:
- * Change CPT slug name from the slug/permalink
- **/
- function remove_cptname_from_slug( $post_link, $post, $leavename ) {
- if ( 'docs' != $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', 'remove_cptname_from_slug', 10, 3 );
- /**
- * Step 2:
- * Change CPT slug name from query request
- **/
- function parse_cptname_on_query_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', 'docs', 'page' ) );
- }
- }
- add_action( 'pre_get_posts', 'parse_cptname_on_query_request' );
Advertisement
Add Comment
Please, Sign In to add comment