1

I'm working on remaking a big website with its upload folder already full of many gigabits of images. I just noticed a problem I never noticed with WordPress before: it seems to create attachment pages based on the name of the images, which means that it "steals" most of the page slugs I want to use.

For example, let's say I have an image named about.jpg in my upload folder. The URL mysite.com/about will be created and automatically redirect to that image. Now, if I want to create a regular page named About, the URL doesn't have the priority on the attachment and will be forced be called mysite.com/about-2.

It's quite frustrating to not have clean URLs, and I haven't found much on the web about it, which is strange. It tried the filter mentioned here but it doesn't seem to do anything. Any help would be appreciated. Thank you :)

2
  • The filter would probably only work if you set it up before importing the images. If your images are already imported then I guess you either want some behaviour to spot if an image already has a slug on page save and rename it out of the way, or just e.g. run some SQL to change all the slugs where post_type = 'attachment'? Is that something you could try, after you've taken a database backup?
    – Rup
    Oct 25, 2020 at 13:16
  • Thanks for you answer :) This is indeed what I ended up doing. I just changed the slugs that I needed in the database, and they became available. Oct 26, 2020 at 11:32

1 Answer 1

3

I've found a workaround if someone has the same problem:

In the database, you can search for the attachment page that's causing problem, you'll find it in wp_posts by searching for its post_name (which is the slug you want). Then just rename that post_name (in about-img for example). It isn't a fix but it will make the desired slug available for your page's URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.