Skip to content

Instantly share code, notes, and snippets.

@nathaningram
Created April 7, 2022 19:55
Show Gist options
  • Select an option

  • Save nathaningram/b6aff36f3d0cd48873a41519061935c3 to your computer and use it in GitHub Desktop.

Select an option

Save nathaningram/b6aff36f3d0cd48873a41519061935c3 to your computer and use it in GitHub Desktop.
Remove Slug from CPT URLs
//Removes Slugs from CPT URLs
function na_remove_slug( $post_link, $post, $leavename ) {
if ( 'linked_article' != $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', 'na_remove_slug', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment