Last active
May 22, 2024 17:27
-
-
Save jeremyjaymes/9ee1505f346d15578bb6 to your computer and use it in GitHub Desktop.
WordPress Get Attachment File Type Extension
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 | |
/** | |
* Get attachment file type extension | |
* | |
* Requires that you have the attachment id | |
* See this post http://jeremyjaymes.com/display-attach…ordpress-theme/ for more explanation | |
*/ | |
//* Assumes we're in a loop and have our attachment id already | |
$file_url = wp_get_attachment_url( $file_id ); | |
$filetype = wp_check_filetype( $file_url ); | |
//* Output the link and file type, e.g. "Click to Download | PDF" | |
echo '<p><a href="' . $the_file . '">Click to Download</a> | <span class="filetype">' . $filetype['ext'] . '</span></p>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kudos