├── pt1 - remove slug from cpt permalink └── pt2 - modify cpt query /pt1 - remove slug from cpt permalink: -------------------------------------------------------------------------------- 1 | function na_remove_slug( $post_link, $post, $leavename ) { 2 | 3 | if ( 'events' != $post->post_type || 'publish' != $post->post_status ) { 4 | return $post_link; 5 | } 6 | 7 | $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); 8 | 9 | return $post_link; 10 | } 11 | add_filter( 'post_type_link', 'na_remove_slug', 10, 3 ); 12 | -------------------------------------------------------------------------------- /pt2 - modify cpt query: -------------------------------------------------------------------------------- 1 | function na_parse_request( $query ) { 2 | 3 | if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) { 4 | return; 5 | } 6 | 7 | if ( ! empty( $query->query['name'] ) ) { 8 | $query->set( 'post_type', array( 'post', 'events', 'page' ) ); 9 | } 10 | } 11 | add_action( 'pre_get_posts', 'na_parse_request' ); 12 | --------------------------------------------------------------------------------