Truncate WordPress SEO breadcrumb length

Yoast’s SEO Plugin for WordPress is great. It’s the only SEO plugin I’ve used for years. However there is no control over the length of breadcrumbs it will create. Imagine a long page title breaking your design as the area dedicated to breadcrumbs is notoriously small and narrow.

Here’s how to limit the length in Yoast’s WordPress SEO plugin.

add_filter('wp_seo_get_bc_title', 'truncate_bc_title');
function truncate_bc_title() {
	$title = get_the_title();
 
	$title_length = strlen( $title );
	$limit = 30;
	$truncated = substr( $title, 0, $limit );
 
	if ( $title_length > $limit ) {
		$truncated .= '...';
	}
 
	$link['text'] = $truncated;
 
	return $link['text'];
}

Author: Kieran Barnes

Kieran is a PHP developer with 15 years commercial experience. Specialist in WordPress, CakePHP, CubeCart and all things PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *