By default WordPress does not accept hyperlinks in the widget title. Even if you enter a hyperlink , it will strip down all the html tags and simply print out the text. So basically in order to link the widget titles, we’ll need to find a way to make WordPress accept html in Widget Title.
The Snippet
Here is a little snippet which lets you add a hyperlink in the widget title. The snippet makes use of widget_title filter and it will dynamically replace custom tags with actual html tags. You can use the Code Snippet plugin to run this piece of code.
// We will make use of widget_title filter to
//dynamically replace custom tags with html tags
add_filter( 'widget_title', 'accept_html_widget_title' );
function accept_html_widget_title( $mytitle ) {
// The sequence of String Replacement is important!!
$mytitle = str_replace( '[link', '<a', $mytitle );
$mytitle = str_replace( '[/link]', '</a>', $mytitle );
$mytitle = str_replace( ']', '>', $mytitle );
return $mytitle;
}
So now basically we can enter hyperlinks as [link href = http://google.com]My Widget Title[/link] in our widget title. Take note that we have entered the url without quotes.
This little snippet will make the widget title clickable. If you are not comfortable with coding then you can also achieve the same result by using plugins like Widget Title Links
The post How to Link Widget Titles in WordPress without using a plugin appeared first on SpiceWP.