Skip to content

Instantly share code, notes, and snippets.

@jeremyjaymes
Last active October 4, 2021 06:38
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeremyjaymes/9ee1505f346d15578bb6 to your computer and use it in GitHub Desktop.
Save jeremyjaymes/9ee1505f346d15578bb6 to your computer and use it in GitHub Desktop.
WordPress Get Attachment File Type Extension
<?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>';
@justsomexanda
Copy link

Kudos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment