admin管理员组文章数量:1331538
I want to truncate the menu label to 10 characters, and if the header label is more then it will show 10 characters followed by ... For example: Menu Title: ABCDEFGHIJKLMN It should display the label as ABCDEFGHIJ...
I want to truncate the menu label to 10 characters, and if the header label is more then it will show 10 characters followed by ... For example: Menu Title: ABCDEFGHIJKLMN It should display the label as ABCDEFGHIJ...
Share Improve this question asked Jul 11, 2020 at 23:49 AnikAnik 11 Answer
Reset to default 3Looks like the filter nav_menu_item_title
is what you're after. Here's an example to use that to truncate the title to 10 characters. This is untested, but should do what you want, added to e.g. your 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 );
Does that do it?
本文标签: How to truncate menu label in wordpress
版权声明:本文标题:How to truncate menu label in wordpress? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742269680a2444068.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论