Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if( !function_exists( 'mars_remove_cpt_slug' ) ){
- /**
- * Remove the slug from published post permalinks. Only affect our CPT though.
- */
- function mars_remove_cpt_slug( $post_link, $post, $leavename ) {
- if ( ! in_array( $post->post_type, array( 'video' ) ) || 'publish' != $post->post_status )
- return $post_link;
- $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
- return $post_link;
- }
- add_filter( 'post_type_link', 'mars_remove_cpt_slug', 10, 3 );
- }
- if( !function_exists( 'mars_parse_request' ) ){
- function mars_parse_request( $query ) {
- // Only noop the main query
- if ( ! $query->is_main_query() )
- return;
- // Only noop our very specific rewrite rule match
- if ( 2 != count( $query->query )
- || ! isset( $query->query['page'] ) )
- return;
- // 'name' will be set if post permalinks are just post_name, otherwise the page rule will match
- if ( ! empty( $query->query['name'] ) )
- $query->set( 'post_type', array( 'post', 'video', 'page' ) );
- }
- add_action( 'pre_get_posts', 'mars_parse_request' );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement