我希望将菜单标签截断为10个字符,如果标题标签更多,它将显示10个字符,后面是.例如:菜单标题: ABCDEFGHIJKLMN它应该将标签显示为ABCDEFGHIJ.
发布于 2020-07-12 04:06:09
看来过滤器nav_menu_item_title
就是你要找的东西。下面是一个示例,用于将标题截断为10个字符。这是未经测试的,但应该做您想做的事,添加到您的functions.php
中
function filter_nav_menu_item_title( $title, $item, $args, $depth ) {
$truncLength = 10;
if (strlen($title) > $truncLength) {
return substr($title, 0, $truncLength) . "...";
} else {
return $title;
}
}
// add the filter
add_filter( 'nav_menu_item_title', 'filter_nav_menu_item_title', 10, 4 );
这样行吗?
https://wordpress.stackexchange.com/questions/370889
复制相似问题