Last active
June 16, 2022 20:33
-
-
Save kaelri/a88f813b682ab9ae39f7ce4eec597140 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'get_header', function() { | |
if ( !is_attachment() ) return; | |
$file_url = wp_get_attachment_url( get_the_ID() ); | |
$file_name = basename( $file_url ); | |
header( sprintf('Content-type: %s', get_post_mime_type() ) ); | |
header( sprintf('Content-Disposition: attachment; filename="%s"', $file_name ) ); | |
readfile( get_attached_file( get_the_ID() ) ); | |
exit; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment