最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Attachment pages stealing page slugs

programmeradmin2浏览0评论

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/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/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 :)

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/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/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 :)

Share Improve this question asked Oct 24, 2020 at 9:54 morceaudeboismorceaudebois 713 bronze badges 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 Commented 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. – morceaudebois Commented Oct 26, 2020 at 11:32
Add a comment  | 

1 Answer 1

Reset to default 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论