Skip to content

Instantly share code, notes, and snippets.

@KimBranzell
Last active June 17, 2016 09:16
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 KimBranzell/240ec7a699e759f371cb385549769fbf to your computer and use it in GitHub Desktop.
Save KimBranzell/240ec7a699e759f371cb385549769fbf to your computer and use it in GitHub Desktop.
Updates a post's slug whenever "Upload" or "Published" are pressed.
function update_post_slug( $data, $postarr ) {
if ( ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
$data['post_name'] = wp_unique_post_slug( sanitize_title( $data['post_title'] ), $postarr['ID'], $data['post_status'], $data['post_type'], $data['post_parent'] );
}
return $data;
}
add_filter( 'wp_insert_post_data', 'update_post_slug', 99, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment