Created
May 21, 2013 14:26
-
-
Save jhebb/5620190 to your computer and use it in GitHub Desktop.
Allows you to define a link that is wrapped around WordPress widget titles.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Description: Allows you to define a link that is wrapped around widget titles. | |
Author: Justin Hebb - Jukah Digital | |
Based on: Plugin by Dustin Dempsey - Playforward | |
*/ | |
function widget_title_link( $title ) { | |
// assume there's a link attached to the title because it contains a '|' followed by www., http, or / | |
if ( preg_match('/\|(www.|http|\/).*/', $title) ) { | |
// split our title in half | |
$title_pieces = explode( "|", $title ); | |
// if there's two pieces | |
if ( count( $title_pieces ) == 2 ) { | |
// add http if it's just www | |
if ( substr( $title_pieces[1], 0, 4) == "www." ) { | |
$title_pieces[1] = str_replace( "www.", "http://www.", $title_pieces[1] ); | |
} | |
// create new title from url and extracted title | |
$title = '<a href="' . $title_pieces[1] . '" title="' . $title_pieces[0] . '">' . $title_pieces[0] . '</a>'; | |
} | |
} | |
return $title; | |
} | |
add_filter( "widget_title", "widget_title_link" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment