Convert With Ben

If you’ve ever tried to set up a category or page slug—only to find WordPress redirecting it to an image—you’re not alone. It’s caused by WordPress creating attachment posts for every uploaded file, which can silently claim the same URL slugs you want.

You can fix this by renaming your attachment slugs, preventing future conflicts. Here’s how.


🧩 The Problem: Image Slugs Hijack Your Pages

When you upload an image, WordPress creates an attachment post with a slug based on the image title:

/citizenship/

That means if you later create a page or category at /citizenship/, WordPress may redirect to the image instead.

Even if you’re using Yoast SEO to redirect attachment pages to the image file, the slug still stays reserved, blocking your content.

🔍 Why It Happens

WordPress stores media items as posts in the wp_posts table. Each post has a post_name (slug), and attachments work the same way. If that slug already exists, WordPress won’t let you reuse it.

✅ The Solution: Prefix All Attachment Slugs

A clean fix is to add a prefix, such asimage-, to every attachment slug. For example:

/image-citizenship/

This clears up /citizenship/ for your real content.


🛠 How to Do It (Step‑by‑Step)

  1. Backup wp_posts tableIn phpMyAdmin, run:
    CREATE TABLE wp_posts_backup AS
    SELECT * FROM wp_posts;
    

    (Screenshot: show phpMyAdmin “Export” or “SQL” screen.)

  2. Update all attachment slugsRun this SQL:
    UPDATE wp_posts
    SET post_name = CONCAT('image-', post_name)
    WHERE post_type = 'attachment'
    AND post_name NOT LIKE 'image-%';
    

    This renames everything like citizenshipimage-citizenship.

  3. Flush permalinksIn Settings → Permalinks, click Save Changes to apply the new slugs.

    (Screenshot: Permalinks settings with “Save Changes” button highlighted.)


🧼 Bonus: Redirect Old Slugs

If /citizenship/ was already in use, set up a redirect to your page or category:

  • Use a plugin like Redirection
  • Or add a 301 redirect in your .htaccess:
    Redirect 301 /citizenship/ /citizenship-category/
    

✅ Final Thoughts

WordPress attachment slugs can quietly hijack your intended URLs. By prefixing attachment slugs, you stop that confusion and take back control of your site structure.

Let me know if you want help automating this for future uploads or assistance writing the SQL query better.