This script will do the job:
function wpse_287807_replace_url() {
// Get all posts
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => -1,
));
$posts = $query->get_posts();
foreach ($posts as $post) {
// Get permalink
$url = $post->post_name;
// Stop words array
$stop_words = array(
'-a-',
'-the-',
'-of-',
);
// Replacement
$replacement="-";
// Replace url
$new_url = str_replace($stop_words, $replacement, $url);
// Prepare arguments
$args = array(
'ID' => $post->ID,
'post_name' => $new_url,
);
// Update post
wp_update_post( $args );
}
}
add_action('init', 'wpse_287807_replace_url');
If you have many posts disable creating revision
posts by adding WP_POST_REVISIONS
constant to wp-config.php
. It will speed up script and reduce the demand for memory usage.
define( 'WP_POST_REVISIONS', false );