Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellenmace/b39553b3c7243ff62040 to your computer and use it in GitHub Desktop.
Save kellenmace/b39553b3c7243ff62040 to your computer and use it in GitHub Desktop.
Remove Custom Post Type Slug from Permalinks
/**
* Remove the slug from published post permalinks. Only affect our CPT though.
*/
function gp_remove_cpt_slug( $post_link, $post, $leavename ) {
if ( 'race' != $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', 'gp_remove_cpt_slug', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment