Change Attachment Post URLs to File URLs

Create an attachment template file within the theme. Since we are only interested in images, the file should be image.php

<?php 

if ( have_posts() ) { 
    the_post(); 
    $image_url = wp_get_attachment_url();
}

header('Location: '.$image_url);

?>

Template Hierarchy

Leave a Comment

error code: 523