Created
April 8, 2020 18:04
-
-
Save ozamancse/0a21c28f847be3b765060b59d81c8a18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| function tmf_remove_slug( $post_link, $post, $leavename ) { | |
| if ( 'practice-area' != $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', 'tmf_remove_slug', 10, 3 ); | |
| function tmf_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', 'practice-area', 'page' ) ); | |
| } elseif ( ! empty( $query->query['pagename'] ) && false === strpos( $query->query['pagename'], '/' ) && 'blog' != $query->query['pagename'] ) { | |
| $query->set( 'post_type', array( 'post', 'practice-area', 'page' ) ); | |
| // We also need to set the name query var since redirect_guess_404_permalink() relies on it. | |
| $query->set( 'name', $query->query['pagename'] ); | |
| } | |
| } | |
| add_action( 'pre_get_posts', 'tmf_parse_request' ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment