I’ve been working on using some icons for links in a new theme that I’m building. I wanted to let the client link to any kind of file or web page, and then the theme would detect the file type and apply the appropriate icon. Something like this:
You can see that the two links have different icons. The first is a link to a PDF document, and the second is a link to a web page.
Here’s the code I used to solve the problem. It could possibly be a bit more elegant! Please suggest any improvements here: https://gist.github.com/keithdevon/db6e90f4a419c4a2c08b