• Hi

    I wanna redirect all my attachment pages directly to the media file itself instead of showing the attachment page.

    Can anybody help me with that?

    • This topic was modified 7 years, 2 months ago by Andris.
    • This topic was modified 7 years, 2 months ago by Andris.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Is it not possible to directly link to the media files?

    If not, you have to use something like this (to be put e.g. in you (child) theme’s functions.php)

    
    add_action( 'template_redirect', 'your_prefix_attachment_redirect' );
    function your_prefix_attachment_redirect() {
      if ( is_attachment() ) {
        wp_redirect( wp_get_attachment_url( get_the_ID() ), 301 );
        exit();
      }
    }
    
    Anonymous User 15646442

    (@anonymized-15646442)

    Perhaps this article by WP Beginner can help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Attachment page redirect to media file’ is closed to new replies.