因为@toscho已经回答了here, 是的,这是可能的。
您只需将此代码复制到functions.php
这就是你的主题。
// 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
)
);
}
}
如果创建
yourplugin.php
插件文件夹中的文件,带有有效的插件头和以上代码:
<?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
?>
请注意,如果您将此代码复制到
functions.php
或者激活插件,它会一直执行。在这里,您可以了解如何只执行一次代码:
Best Practices