Answers for "multiple post slug remove"

0

multiple post slug remove

function dd_remove_posttype_slug( $post_link, $post, $leavename ) {
    if ( ! in_array( $post->post_type, array( 'your-post-type1', 'your-post-type2' ) ) || 'publish' != $post->post_status )
        return $post_link;
    $post_link = str_replace( '/your-post-type-slug1/', '/', $post_link );
    $post_link = str_replace( '/your-post-type-slug2/', '/', $post_link );
    return $post_link;
}
add_filter( 'post_type_link', 'dd_remove_posttype_slug', 10, 3 );
function dd_parse_request_posttype( $query ) {
    if ( ! $query->is_main_query() )
        return;
    if ( 2 != count( $query->query )
        || ! isset( $query->query['page'] ) )
        return;
    if ( ! empty( $query->query['name'] ) )
        $query->set( 'post_type', array( 'post', 'page', 'your-post-type1', 'your-post-type2' ) );
}
add_action( 'pre_get_posts', 'dd_parse_request_posttype' );
Posted by: Guest on October-19-2021

Browse Popular Code Answers by Language