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.
Hi..Dee Teal, It is nothing but a graphic design with word press which is most attractive for your customize website, Moreover you are talking about the fabulous little plugin called Image Widget. which facilitates you to work with an image. thanks for your Nice post.
My pleasure, Albert. Thanks for the comment!
This is exactly what I have been looking for thank you so much for sharing! Really great site too 🙂
Thanks Nicola, glad I could be of help!
Howdy,
I found reference to your article in the CobaltApps site, creators of Dynamik Website Builder for Genesis.
I’ve tried this script because all I need are Widget Title Links but I get a PHP error as soon as I load this to my custom functions file. I don’t know PHP but this seems pretty straight forward. Does this work with the newest Genesis? Do you see anything wrong with this script?
<?php
function html_widget_title( $title ) {
//HTML tag opening/closing brackets
$title = str_replace( '[a', '<a', $title );
$title = str_replace( '[/a]', '‘, $title );
return $title;
}
add_filter( ‘widget_title’, ‘html_widget_title’ );
?>
Please ignore my previous post. I found the issue.
I take that back. I can make it so the PHP code doesn’t error out but the Function doesn’t perform as expected. The HTML code it writes is completely garbled for some reason.
Hey Robert, how is it garbled? Can you show me an example?
Nice Post