Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MattRyanCo/afedd478276ac0079012fc11f4941ec5 to your computer and use it in GitHub Desktop.
Save MattRyanCo/afedd478276ac0079012fc11f4941ec5 to your computer and use it in GitHub Desktop.
Make Widget Title Linkable
// 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;
}
@MattRyanCo
Copy link
Author

MattRyanCo commented Jun 7, 2017

Replaces widget title: [link href=/contact/]Contact Us[/link]
with <a href="/contact/">Contact Us</a>

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