I am using a simple function to pull all PDF and MSWord documents attached to a post (a custom post-type) and return them in an unordered list for download, like so:
You could wrap that post_mime_type property in a function that translates it to your "simpler" format. Probably a simple map of mimeTypes => friendlyMimeTypes
I don't know where in WP you define your custom functions. I believe it's in functions.php, yes. As long as the function is defined somewhere where it will be available when you try to use it, you're fine.
You would use this function in your code above instead of printing out the post_mime_type directly:
// instead of echo $attachment->post_mime_type; // you would use echo friendly_mime( $attachment->post_mime_type );
Simple enough. But the outputted HTML return "Download XYZ Document Title (application/pdf)".
I want it to return a 'friendlier' name for the file type, like so, "Download XYZ Document Title (PDF)"
Is there any way to achieve this?
Thanks in advance for any help.
post_mime_typeproperty in a function that translates it to your "simpler" format. Probably a simple map of mimeTypes => friendlyMimeTypesI've only ever used a translate function to change "Posts" to say "Articles"... But even that was from a tutorial.
Any hints / snippets?
$attachment->post_mime_typeprints outapplication/pdf, then you could do something like this:My code above resides in archive-downloads.php
I am echo-ing the resulting text, not printing.
Feel a bit stupid right now... Where are you suggesting your snippet should go - functions.php? Also, how does the "print friendly_mime" but fit in..?
echois an alias forprint.I don't know where in WP you define your custom functions. I believe it's in functions.php, yes. As long as the function is defined somewhere where it will be available when you try to use it, you're fine.
You would use this function in your code above instead of printing out the post_mime_type directly:
Thanks Traq and Schmotty - worked like a charm and I've learnt something new.
Cheers