Regenerate Slugs From Title of Posts

Yes, it is possible.

Sample code, has to be tested and refined:

// get all posts
$posts = get_posts( array (  'numberposts' => -1 ) );

foreach ( $posts as $post )
{
    // check the slug and run an update if necessary 
    $new_slug = sanitize_title( $post->post_title );
    if ( $post->post_name != $new_slug )
    {
        wp_update_post(
            array (
                'ID'        => $post->ID,
                'post_name' => $new_slug
            )
        );
    }
}

I just made this up, there are probably some errors and egde cases, but it should give you an idea. Also, this may take a while, so it could be useful to split the update into smaller chunks.

Leave a Comment