Created
July 11, 2018 03:40
-
-
Save namncn/b112cb6c799dc90045bff4f0e65f7bb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Remove custom post type slug from URL. | |
*/ | |
function pdvn_remove_slug( $post_link, $post, $leavename ) { | |
if ( 'product' != $post->post_type || 'publish' != $post->post_status ) { | |
return $post_link; | |
} | |
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); | |
// $post_link = str_replace( '/san-pham/', '/', $post_link ); If used: $args['rewrite'] = array( 'slug' => 'san-pham' ); | |
return $post_link; | |
} | |
add_filter( 'post_type_link', 'pdvn_remove_slug', 10, 3 ); | |
/** | |
* [pdvn_parse_request description] | |
*/ | |
function pdvn_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', 'product', 'page' ) ); | |
} | |
} | |
add_action( 'pre_get_posts', 'pdvn_parse_request' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment