Skip to content

Instantly share code, notes, and snippets.

  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kellenmace/a79dfde1e5a14d51a8014d880dac52e7 to your computer and use it in GitHub Desktop.
Remove custom post type slug from permalinks in WordPress
<?php
/**
* Remove the slug from published post permalinks. Only affect our custom post type, though.
*/
function gp_remove_cpt_slug( $post_link, $post ) {
if ( 'race' === $post->post_type && 'publish' === $post->post_status ) {
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
}
return $post_link;
}
add_filter( 'post_type_link', 'gp_remove_cpt_slug', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment