So, in this game from time to time you get thrown a curveball. Some beautiful design feature that doesn’t have a natural easy flowing way of working in WordPress.
Here’s the scenario.
This design has lovely images that are also links, in the sidebar. The titles for said widget are overlaid on the images, and thus also need to be links.
Now, in the interests of making things easy for the end user we’re working with a fabulous little plugin called Image Widget. This offers a really easy way to get nice images, using the WordPress media library etc. into your widget areas. Because, yes, while I know I could have put the HTML into a text widget, NOT used the title, and just coded a linked title in that widget box, that isn’t exactly user friendly.
However, it is also not possible to write the HTML around the title in order to create a link as WordPress by default strips HTML in widgets.
So, in one solution, I could have added in a plugin that allows text in titles, but it seems that in most cases such plugins are rolling their own widget box, so I’d be reduced back to using the text type widget… this doesn’t help me! I really want to use the Image Widget Plugin!
Moving on, and after a bit of googling (where I found this http://wp-snippets.com/simple-html-in-widget-title) and adding some tweaks of my own… here’s what I’ve got.
It’s a pretty basic string replace… Instead of using angled brackets to wrap around my link I use square ones… like this..
[a href="http://mylink.com"]Link to My Link[/a]
and the script (which I pasted into the functions.php) simply does that string replace before it renders the page, WordPress doesn’t catch on that we’re writing HTML, and the browser gets the angled brackets, therefore the text gets the link. Easy peasy! SO, while it’s marginally more challenging for the end user than being able to just paste a link in the plugin (nudge, nudge, plugin devs) it does at least achieve what we need without having to COMPLETELY write an HTML based widget.