Force post slug to be auto generated from title on save

The easiest workaround could be:

function myplugin_update_slug( $data, $postarr ) {
    if ( ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
        $data['post_name'] = sanitize_title( $data['post_title'] );
    }

    return $data;
}
add_filter( 'wp_insert_post_data', 'myplugin_update_slug', 99, 2 );

Leave a Comment