• Home
  • About
  • Now
  • Code Snippets
  • Blog
    • WordPress
    • Genesis Theme Framework
    • Tutorials
    • Web Development
    • Geeking Out
    • Blogging Resources
  • Contact
  • Home
  • My Story
  • Now
  • Code Snippets
  • Blog
  • Contact

The Web Princess

WordPress & Genesis Theme Development

The Web Princess

How to Link Widget Titles Without a Plugin

September 19, 2013 by Dee Teal

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.

About Dee Teal

Dee Teal is a Scrum Master, Project Manager, and Team leader with a history as a developer (mostly front-end and using the Genesis Theme Framework) and WordPress trainer who is crazy active in the WordPress community.

She's run large scale WordPress events, and small ones, and if you ask someone about WordPress in Australia, you won't usually be more than one degree of separation from someone who knows her.
 
You can also find her here...
LinkedIn | Twitter

Comments

  1. Albert P says

    September 24, 2013 at 10:45 pm

    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.

    • Dee Teal says

      September 28, 2013 at 8:07 pm

      My pleasure, Albert. Thanks for the comment!

  2. Nicola says

    September 28, 2013 at 1:12 am

    This is exactly what I have been looking for thank you so much for sharing! Really great site too 🙂

    • Dee Teal says

      September 28, 2013 at 8:06 pm

      Thanks Nicola, glad I could be of help!

  3. Robert Shepherd says

    January 2, 2014 at 6:32 am

    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’ );
    ?>

  4. Robert Shepherd says

    January 2, 2014 at 6:34 am

    Please ignore my previous post. I found the issue.

  5. Robert Shepherd says

    January 2, 2014 at 6:48 am

    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.

    • Dee Teal says

      January 3, 2014 at 12:29 pm

      Hey Robert, how is it garbled? Can you show me an example?

  6. e Park Ltd says

    January 16, 2014 at 6:47 am

    Nice Post

FREE Website Planner

  • Become your web designer's favourite client

Website Sign Ups

Become your Web Designer's favourite client by preparing for your web project using the Web Princess' Interactive Website Planner

  • This field is for validation purposes and should be left unchanged.

Tweet

  • I just solved pack Snake in WordBrain - as number 2605 ever! #wordbrain #genius #words http://t.co/ygULwZTRYQ http://t.co/ORNxwtaTIl September 14, 2015 2:11 pm
  • Pretty impressed with the stops that @Telstra are pulling out to get my issues sorted... Service with a surprised smile! September 14, 2015 2:48 am
  • It's Tuesday. A perfect evening for this. And by this I mean beer (of course). #oohermrs… https://t.co/eiIttD5xWa September 8, 2015 8:17 am
  • Follow Along

Recent Posts

  • Moving to deeteal.com October 23, 2020
  • Asking a Better Question September 13, 2016
  • Growing & Developing your WordPress Meetup June 24, 2016
  • Making an Escape June 7, 2016
  • Changing Tack : Adjusting your Sails for the Winds of Change May 7, 2016
  • Privacy Policy
  • Disclosure Policy
  • Contact

© 2023 The Web Princess
Proudly custom built with Genesis