+8 votes
in Tutorials and Guides by (1.5m points)

How to remove old slugs in WordPress

1 Answer

+9 votes
by (725k points)
Best answer

In WordPress when we edit the slug of an entry it automatically creates a redirection from the old URL to the new one, in order to avoid problems. Creating redirection is the best option by default, but sometimes we need to remove old slugs in WordPress and in this article I will show you how to do it.


Imagine that the old URL we share on the network, when editing it people would no longer find that resource, hence WordPress is benevolent and always creates a redirection. This redirection also allows us to maintain the SEO of our page, transmitting the authority of the old URL to the new one, thanks to the redirection.

Personally I have encountered situations in which I needed to eliminate the old slug and do without that permanent redirection 301 and WordPress does not make it easy for us to eliminate it.

How to remove old slugs in WordPress

In the article I will explain in detail how to remove old slugs in WordPress through the console, using SSH and also in a graphical way using PhpMyAdmin. For this task we will modify the database directly, so be careful and as always, make a backup copy of the database before continuing.

Remove slugs from WordPress with PhpMyAdmin.

First we have to locate the wp_postmeta table in the database of our WordPress blog. In the contents of this table we have to look at the meta_key and meta_value columns, so that in the first one it says _wp_old_slug and in the second one the slug that we want to eliminate.


When we have located the slug, we only have to press where it says delete and the slug is permanently deleted, so there will be no redirection.

Remove slugs from WordPress through the SSH terminal.

The first thing we have to do is access the database, for this we use the following command:
mysql -u usuario -p basededatos

After executing this command you will ask us to enter the password.

To see all the old slugs we can execute the following request:
SELECT * FROM `wp_postmeta` WHERE `meta_key` = '_wp_old_slug';

Once we have located the slug that we want to eliminate, we execute the command:
DELETE FROM `wp_postmeta` WHERE `meta_key` = '_wp_old_slug' AND `meta_value` = 'slug-que-quiero-borrar';

In case we wanted to eliminate all old slugs, the request would be as follows:
DELETE FROM `wp_postmeta` WHERE `meta_key` = '_wp_old_slug';

Once we have finished deleting the slugs, we execute the following command to exit the mysql console:

I hope this tutorial has helped you, because unfortunately I have not found any plugin that allows you to manage old slugs. If you have any questions or suggestions to improve the tutorial, do not hesitate to use the comments.

Most popular questions within the last 20 days