Last active
February 22, 2017 16:23
-
-
Save DougBeney/1551fe39ef9bcccd273c2dda6301dbce to your computer and use it in GitHub Desktop.
Truncate Yoast Breadcrumb Titles
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
<?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