Last active
October 8, 2024 19:05
-
-
Save robneu/7743769 to your computer and use it in GitHub Desktop.
Truncate the title of Yoast's WordPress SEO breadcrumbs.
Improved @keefyhub code to avoid cutting UTF8 chars in half (and avoid breadcrumbs like "sin�…").
function shorten_yoast_breadcrumb_title($link_info) { $limit = 32; if (strlen($link_info['text']) > ($limit)) { $link_info['text'] = substr( $link_info['text'], 0, strpos($link_info['text'], ' ', $limit) // added: cut at the first white space after limit ) . '…'; } return $link_info; } add_filter('wpseo_breadcrumb_single_link_info', 'shorten_yoast_breadcrumb_title', 10);
Its working on the latest version of Yoast
@vj009007 - Just use the core WordPress wp_trim_words() function which takes care of all that for you ;)
https://developer.wordpress.org/reference/functions/wp_trim_words/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work now.