How to generate slugs?

As @toscho already answered here, yes this is possible.

You just need to copy this code into the functions.php of your theme, and there you go.

// 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 );

    // use this line if you have multiple posts with the same title
    $new_slug = wp_unique_post_slug( $new_slug, $post->ID, $post->post_status, $post->post_type, $post->post_parent );

    if ( $post->post_name != $new_slug )
    {
        wp_update_post(
            array (
                'ID'        => $post->ID,
                'post_name' => $new_slug
            )
        );
    }
}

You can also create a plugin for that, if you create a yourplugin.php file in your plugins folder, with a valid plugin header and the above code:

<?php
    /*
    Plugin Name: Your Plugin
    Plugin URI: http://www.example.com
    Description: description
    Version: 0.1
    Author: thatsyou
    Author URI: http://www.yourdomain.com
    License: MIT
    */

    //yourcode
?>  

Please be aware that if you copy this code into your functions.php or your activate the plugin, it is executed all the time. You can get some ideas on how to execute code only once here: Best Practices

Leave a Comment