Skip to content

Instantly share code, notes, and snippets.

@Antoinebr
Created February 16, 2016 21:54
Show Gist options
  • Select an option

  • Save Antoinebr/ab38f8068747fdec9516 to your computer and use it in GitHub Desktop.

Select an option

Save Antoinebr/ab38f8068747fdec9516 to your computer and use it in GitHub Desktop.
wp-regenerate-slug.php
<?php
$posts = get_posts(array(
'post_type' => 'page',
'post_status' => 'publish',
'orderby' => 'menu_order',
'numberposts' => 999999
));
foreach ( $posts as $post )
{
$new_slug = sanitize_title( $post->post_title );
if ( $post->post_name != $new_slug )
{
wp_update_post(
array (
'ID' => $post->ID,
'post_name' => $new_slug
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment