Finding and Fixing Duplicate Slugs in WordPress
Do you have posts or pages with -2 or even -3 or 4 or 5 on them? I’ll show you how to find the original one and get rid of the duplicates!
Thanks to Isis Casalduc for reminding me of this issue!

This tip was sponsored by OSTraining.com! OSTraining aims to explain websites so clearly that anyone can understand, with jargon-free, hands-on training that clearly defines processes to simplify complex tasks. OSTraining offers online courses, best-selling books, onsite training, and online live training.
More than 100,000 students have learned website development through OSTraining. OSTraining courses focus on web development and the tools around it, including WordPress, WooCommerce, Drupal, Magento, and Joomla.
Transcription
Hey folks, welcome to another HeroPress Tip of the Week. This week we’re going to talk about duplicate slugs and how to fix them. This last week, my friend Isis posted on Twitter that she had a URL that kept showing up as Gaspard dash two, when it was not a duplicate page, there was another there was not another page out there with that slug.
Well, as it turns out, she had an image that was called Gaspard dot something probably jpg. And when she uploaded it, it created a media page with that slug. Now part of the problem was is it shows here in Twitter’s that she had bulk uploaded a ton of images. So it’s not like she remembered uploading gasp bar, but it was still there, and it’s still got her. And so we’re gonna look at two different scenarios, one similar to hers and one, much worse.
So I set up a local site just like hers, I have a page here called gaspar. And as you can see right here, my slug is gaspar dash two. And that’s because I made an image called gaspar.jpg and uploaded it. You can see here’s the title, there’s the file name. But you don’t see right here that it has a slug that its page has a slug. But if you view attachment page, then you can see in the URL, it’s just gaspar. So one relatively easy way to figure out where the first one is, is to go to any of the numbers, if she added a third or fourth and fifth, it would do dash three, dashboard, f5, etc. And you could end up with a bunch of these.
But you could just take that off and go there, it will show you the first one. And when you’re on this page, you can see at the top, it says Edit media, that’s your first clue that this is a media item, not a post or page. And then if you go to it, it takes you to this page. And you can do a variety of things with it. But you can’t change the slug here. So if you want to use Gaspar on a page, you have to delete this image, make the page and then rename the image to something else and re upload it, which can be a bit of a pain. But that’s the way it goes sometimes. It is possible if you get into the database to change the slug if you’re very, very careful. And we’ll look at that in a minute.
Now I mentioned that you can end up with dash three, dash four, dash five, etc. That often happens when you are importing a site. And either the first one fails or the second one times out, and so on and so forth. And you try it three or four or five times, and then you end up with duplicates of some pages, but not all pages. And it’s just it’s horrible. So an easy way to figure out what’s going on is to go into the database. So we’re going to use PhpMyAdmin. And I’m going to show you real quick, where you can find PhpMyAdmin. Most hosts have it in their panel.
This is the SiteGround panel. And if you go under site, there’s MySQL. And right here is PhpMyAdmin. And you click it it just pops up, pops it up in a tab you don’t even have to log in piece of cake. This is an access. Again, looking at a panel for a site. If you go to show more. There’s databases. And right here is launch PhpMyAdmin. Most hosts have it similarly presented, you go to the panel, you find your database stuff, and there’s a link to PhpMyAdmin. So this one, I’m running local WP and I installed PhpMyAdmin on it just so we could use it. So if we go into local and go to the posts table, you’ll see that there are eight things in here. There’s the default.
Welcome page, there’s a default. I can’t remember the name of it. Let’s see here.
Privacy Policy, this privacy policy sample page. There’s a default post, etc. So we want to find anything with a dash two I’m going to cheat a little bit, we only have eight things here, what if you had 1500, it’d be really hard. Here are our two gaspar sites. And you can see there’s gaspar and dash two. And so And pay attention. This column name is post name, it’s not slug, like it should be. So at the top in PhpMyAdmin, you can choose Search. And we go down to dash name, you can search for fragments, if you click this down arrow box and choose, like with percent signs. Let it go. So it found number two. So you can choose number three, number four, etc. Or we can also let’s do search, go to name search just for the prefix. Now you see it shows both of them. This is really helpful when you have seven or eight copies of some pages. And you want to know, you can search for the prefix and find out which which sites have multiple pages, you can go ahead and search for Dash eight and find out how many posts have a copies. Because if it says there’s 25 results, then you probably have 25 posts that have up to eight copies. So I mentioned that you can edit these if you’re very careful. So I’m going to click edit right here, we’ll go down to name and this is going to become dash image.
I’m going to hit go. And you’ll see it did it. Now I can do the same thing here, I can take off the dash two. But instead, what I’m going to do is use it properly. With a quick edit, take off the dash to an update in a quick edit again, and it stayed off. So now while it’s just view this page, there it is gaspar. So you can potentially do multiples in here. I don’t recommend you delete posts, in PhpMyAdmin. Because every post has a bunch of post meta. So for example, I’m going to look up post number six.
So if I had deleted the page, which is post number six, these two things would have been left here as orphans, which isn’t terrible. But if you’re doing hundreds of pages, you’re going to end up with 1000s of fields. And that just gets messy and slows down your database. And you don’t want that. So to review, a quick way to find the original is to just remove all the numbers from the URL and go there. And it will show you whether it’s a poster or a page or whatever. And then you can edit it and do whatever you need to do. If you have multiples, I recommend research in data in the database and finding out which ones have multiples. But then going in here and deleting. So for example, let’s say I had guessed by one through eight, in awhile, you know, I’ll just will do
this I’m going to make a second page.
And you can see my slug now has dash twoyou can but from here you can’t see that you don’t know which ones are which. So I would search here for gaspar. And knowing from the database, which ones have which IDs, you can figure out which one you want to keep. And then you can do this kind of thing. See this one is this was dash two. So we’re going to keep that one and I would choose this one and the other six siblings and move to trash. And that takes care of all of your metadata and all that kind of stuff. Now in ISIS, his case, she needed to keep both of them. They weren’t actually duplicates. They were just two different things named the same thing. And so we really able to rename one of them, give it a new slug. and name the one that needed the, the just the Gaspar name properly. And that worked great. So there you have a variety of options and variety of tools for research.
I hope you find this useful.