How to truncate menu label in wordpress?

I want to truncate the menu label to 10 characters, and if the header label is more then it will show 10 characters foll

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 1
Add a comment  | 

1 Answer 1

Reset to default 3

Looks 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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742269680a4412462.html

相关推荐

  • How to truncate menu label in wordpress?

    I want to truncate the menu label to 10 characters, and if the header label is more then it will show 10 characters foll

    2天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信