0

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...

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.