Created
July 8, 2016 07:36
-
-
Save kirandash/7aabf1681b40aacf761a2ba8cb74961e to your computer and use it in GitHub Desktop.
Set bloginfo with two different colors. Wrap the first word of the blog title with the <span>...</span> tag.
This file contains 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
//Set bloginfo with two different colors | |
/** | |
* Wrap the first word of the blog title with the <span>...</span> tag. | |
* Assumes the Twenty Twelve theme. | |
* | |
* @see http://stackoverflow.com/a/25096093/2078474 | |
*/ | |
add_filter( 'body_class', | |
function( $class ) | |
{ | |
add_filter( 'bloginfo', 'so_25094932_modify_first_word', 10, 2 ); | |
return $class; | |
} | |
); | |
function so_25094932_modify_first_word( $output, $show ) | |
{ | |
// Target the "name" part: | |
if( 'name' === $show ) | |
{ | |
// Target the second instance: | |
remove_filter( current_filter(), __FUNCTION__ ); | |
// Modify the first word of the blog title: | |
$title = explode( ' ', $output ); | |
if( count( $title ) > 0 ) | |
{ | |
$title[0] = sprintf( '<span>%s</span>', $title[0] ); | |
} | |
$output = join( ' ', $title ); | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment