Skip to content

Instantly share code, notes, and snippets.

@hauge75
Last active October 7, 2023 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hauge75/9cdceb15c55c7738f7afa8170089ce03 to your computer and use it in GitHub Desktop.
Save hauge75/9cdceb15c55c7738f7afa8170089ce03 to your computer and use it in GitHub Desktop.
Create random slug for custom post
// Create random slug for custom post
function func_update_post_name( $post_id, $post ){
if ( 'post-type-slug' == $post->post_type ) {
remove_action( 'save_post', 'func_update_post_name',30,2 );
// update the post slug
wp_update_post( array(
'ID' => $post_id,
'post_name' => uniqid()
));
add_action( 'save_post', 'func_update_post_name', 30, 2 );
}
}
add_action( 'save_post', 'func_update_post_name', 30, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment