I'm a webdev but have zero wordpress experience, and I'm helping a friend.

So I have permalinks to posts in this format:


However for some reason there are also links in this format that return content:


And the latter format returns a page with the same title, a single image, but none of the text. I'm not sure how and why these latter URLs are being created nor how to remove them. I'd like those URLs to redirect to the actual post (eg https://example.com/some-slug/alternative-categoryA-categoryB-blog-1/ redirecting to https://example.com/some-slug/).

Any idea how I might do this?

Here is a live example:


Those links are called Attachment pages, and Wordpress creates one for each media attachment in a post. There are a few plugins to disable them. To redirect the user to the actual post, one can add the following line of code:

// in wp-content/themes/[your-child-theme]/image.php

<?php wp_redirect(get_permalink($post->post_parent)) ; ?>

Link: https://www.greengeeks.ca/tutorials/article/set-wordpress-to-disable-attachment-pages-for-media/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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