Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
You know those times when you want to make a widget title a link? And WordPress strips HTML? Here's a handy way to do that... Paste the code below in your functions file and then use square brackets instead of angled ones when writing your link around the title. For Example = [a href="http://mywebsite.com"] Link [/a] - WordPress doesn't recogniz…
<?php
add_filter( 'widget_title', 'your_html_widget_title' );
/**
* html_widget_title function.
*
* @access public
* @param mixed $title
* @return void
*/
function your_html_widget_title( $title ) { //HTML tag opening/closing brackets
$title = str_replace( '[', '<', $title );
$title = str_replace( '[/', '</', $title );
$title = str_replace( ']', '>', $title );
return $title;
}
@clifgriffin
Copy link

There's a bug here. Line 16 will never do anything as line 15 will have replaced all [ characters with < characters.

Still useful though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment