In this tutorial, we’ll discuss a common WordPress issue: reclaiming a page permalink (also known as URL or slug) that’s already occupied by an image. We’ll walk you through the process of changing the image’s permalink, so you can name your page URL as desired.
Join +3 610 subscribers!
Understanding Why WordPress Adds The Number”-2″ to your Page URL
All permalinks have to be unique. If you try to add a permalink that already exists, WordPress will automatically add a trailing number to the slug. But, as you probably already noticed, this can also happen if you don’t have a page with the same permalink.
The most likely reason is that images (and videos, pdf:s and other media items) in your WordPress Media Library also have their own permalinks. An image’s permalink is based on the image filename minus the file extension. If you, for example, upload the image products.jpg to your WordPress Media Library, the image URL will be domain.com/products/.
If you try to create a page with a permalink that is already occupied by an image (for example products), WordPress will automatically change the page URL domain.com/products-2 without any notification. That’s not good at all. Luckily, the solution is quick and easy – if you know where to look.
Alternative Method (If the Method Above Doesn’t Work)
If, for some reason, you cannot edit the image’s permalink as described above, you can try the following alternative method:
- Delete the image from your Media Library. Be cautious when doing this, as it will remove the image from your website entirely.
- Next, go to the page where you want to use the deleted image’s permalink.
- Edit the page and change its permalink with your desired slug.
- Save your changes and make sure that the page is published (and not just a draft).
- Finally, re-upload the deleted image. This time the tables has turned and WordPress will add the numerical suffix to the image permalink instead.
All pages and posts that contained the deleted image needs to be updated with the new image URL.
Pro tip: If you don’t want the trailing number to be added to your image’s permalink, just rename the image file name to something unique before uploading it.
That’s all for today!
WordPress provides flexibility when it comes to managing your website’s content and permalinks. By following the steps outlined in this tutorial, you can change an image’s permalink to reclaim a specific page URL. Whether you choose to edit the image’s permalink directly or use the alternative method, you’ll have the freedom to structure your site’s URLs as you see fit. This can help improve your workflow and user experience.
👉 Related post: How To Disable Automatic Image Titles In WordPress
👉 Free course: Create a website from scratch with Divi