For a client’s site I need the site description to break on to a second line at a specific point.
I tried putting a <br /> where I wanted the line break in Settings > General > Tagline but this outputs the characters <br /> rather than the line break. This is because the genesis_seo_site_description function in genesis/lib/structure/header.php (line 983) uses an esc_html on the get_bloginfo( ‘description’ ) – rightly so.
After looking at a few options like restricting the width of the .site-description class in style.css I realised I had another option. I can use the genesis_seo_description filter that is made available just before the site description is echoed.
I first wrote the function below and set it to convert any – (single dash) to a line break. But because the particular site description I was working with had the word ‘Award-winning’ in it I realised the error of my ways and set it to convert ‘ — ‘ instead (space dash dash space).
You can use whatever characters you wish instead of the “space dash dash space”, as long as they are not escaped by esc_html.
You can view this code on github.
add_filter( 'genesis_seo_description', 'jmw_site_description', 10, 3 );
/**
* Add line break to site description at "--" in Genesis child themes
* @link http://www.jowaltham.com/line-break-site-description-genesis
*
* @param string $description The html string that is output as the site description
* @param string $inside The site description in General Settings
* @param string $wrap The html string to wrap around the site description
*
* @return string Modified description
*/
function jmw_site_description( $description, $inside, $wrap ) {
$inside = str_replace( '--', '<br />', $inside );
$description = sprintf( "<{$wrap} %s>", genesis_attr( 'site-description' ) );
$description .= "{$inside}</{$wrap}>";
return $description;
}
I imagine if you wanted to you could employ a similar technique to the genesis_seo_title to add a line break the site title if you wish.
Featured Image: Photo by Cody Davis on Unsplash
Katie
Super handy bit of code; solved an issue I was working on like a charm! Thanks!!