Skip to content

Instantly share code, notes, and snippets.

@DougBeney
Last active February 22, 2017 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DougBeney/1551fe39ef9bcccd273c2dda6301dbce to your computer and use it in GitHub Desktop.
Save DougBeney/1551fe39ef9bcccd273c2dda6301dbce to your computer and use it in GitHub Desktop.
Truncate Yoast Breadcrumb Titles
<?php
//Truncate Breadcrumb title
function truncate_breadcrumb_title() {
// Get the title of the current post.
if(WPSEO_Meta::get_value( 'bctitle', get_the_ID())){
$title = WPSEO_Meta::get_value( 'bctitle', get_the_ID());
}else{
$title = get_the_title();
}
// Determine the length of the title.
$title_length = strlen( $title );
// Set a limit for the breadcrumb title.
$limit = 25;
// Truncate the title.
$truncated = substr( $title, 0, $limit );
// Add an ellipsis if the title has been truncated.
if ( $title_length > $limit ) {
$truncated .= '...';
}
$link['text'] = $truncated;
return $link['text'];
}
add_filter('wp_seo_get_bc_title', 'truncate_breadcrumb_title');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment