Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kirandash/7aabf1681b40aacf761a2ba8cb74961e to your computer and use it in GitHub Desktop.
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.
//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