Hi
how to?
– Truncate the title?
– Truncate the breadcrumb?
– Truncate the title only for mobile?
– Truncate the breadcrumb for mobile?
eva
Hey evas49,
Thank you for the inquiry.
You can try this filter in the functions.php file to truncate the breadcrumb trails.
function avia_breadcrumbs_trail_mod($trails)
{
$newtrails = [];
foreach ($trails as $key => $trail) {
$oldLabel = strip_tags($trail);
$newLabel = substr($oldLabel, 0, 10).'...';
$newtrails[$key] = str_replace($oldLabel, $newLabel, $trail);
}
return $newtrails;
}
add_filter('avia_breadcrumbs_trail', 'avia_breadcrumbs_trail_mod', 50, 1);
For the title, you can try this code.
function max_title_length( $title )
{
$max = 35;
if( strlen( $title ) > $max ) {
return substr( $title, 0, $max ). " …";
} else {
return $title;
}
}
add_filter( 'the_title', 'max_title_length');
You also incorporate the wp_is_mobile function if you want to only apply it on mobile view.
// https://developer.wordpress.org/reference/functions/wp_is_mobile/
Best regards,
Ismael
1: Where do i set the length for the breadcrumb?
2: “You also incorporate the wp_is_mobile function if you want to only apply it on mobile view.”
I dont understand that sentence. It seems to me as if you did not understand what i initially asked
eva