0

When I put something after my domain name that doesn't exist I am taken to my 404 page, for example:

example.com/sdkjhfdsjk

But if I put something that exists as an image I am taken to the page for that, for example:

example.com/imagename

How can I turn this off. I only want to be taken to pages or posts that exist.

UPDATE: This has been marked as a duplicate but the accepted answer to that does NOT fix this.

I added:

remove_action('template_redirect', 'redirect_canonical');

to my themes functions.php but the same action happens.

3
  • Are you talking about images in the media library?
    – s_ha_dum
    Commented Nov 24, 2013 at 16:35
  • Yes, images in the media library.
    – williamsdb
    Commented Nov 24, 2013 at 17:10
  • does it go to an image or to attachment page? Commented Nov 25, 2013 at 11:15

1 Answer 1

0

Try

function no_attachment_page() {
  global $wp_query;
  if ( $wp_query->is_attachment()  ) {
    $wp_query->set_404();
    status_header(404);
    nocache_headers();
  }
}

add_action( 'template_redirect', 'no_attachment_page', 1 );

This should result in a 404 everytime you try to access to an attachment page.

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.