• hello. Im having a puzzling problem…I have several very long category names and cannot change them. I need to be able to use the Category widget in my sidebar for my customers to navigate my site well. When I set this up as a dropdown list, the widget is too wide for the sidebar, creating a horizontal scroll. Ive tried other drop down widgets in the sidebar and the same problem exists. I have read a solution that seemed to work for the author, but does not seem to work for me…here’s the code I found:

    function truncate_list_cats($cat) {
    
        $limit = 25; // do not make this less than 15
    
        if(strlen($cat) > $limi<a href="https://www.bdmperformanceproducts.com">t)
    
            $cat = substr($cat, 0, $limit) . '...';
    
        return $cat;
    
    }
    
    add_filter('list_cats', 'truncate_list_cats');

    This doesn’t work with my theme – elegant themes. Does anyone else have this problem and another solution?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Looks like the function has some extraneous code in it. Try this:

    function truncate_list_cats($cat) {
    
        $limit = 25; // do not make this less than 15
    
        if(strlen($cat) > $limit)
    
            $cat = substr($cat, 0, $limit) . '...';
    
        return $cat;
    
    }
    
    add_filter('list_cats', 'truncate_list_cats');
    Thread Starter laurakshank

    (@laurakshank)

    Hi – Thanks for the help! It still doesn’t work for me tho…I’m not sure why? I’ve added it to my functions.php, and also to the core-functions.php and custom-functions.php files that come with my theme, but it doesn’t work in any of them, and I can see the code in the header of my site…I’m a code newbie, so I may be doing something wrong

    If you can see the code in the output, you probably need to add php tags around it, like this:

    <?php
    function truncate_list_cats($cat) {
    
        $limit = 25; // do not make this less than 15
    
        if(strlen($cat) > $limit)
    
            $cat = substr($cat, 0, $limit) . '...';
    
        return $cat;
    
    }
    
    add_filter('list_cats', 'truncate_list_cats');
    ?>

    You have to be careful when modifying functions.php because an error can cause the site to fail so that you can’t get into the WP editor to fix it. In that case, you have to use ftp or a similar tool to correct the file.

    Thread Starter laurakshank

    (@laurakshank)

    hello. Thanks – I thought that might be the case…and I learned the har way this morning that I could cause the site to fail…scared me, but I was able to correct it thur cPanel..

    I will try this out in some places – thank you again for your help!

    Thread Starter laurakshank

    (@laurakshank)

    This worked perfectly – Thanks!!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Category widgets Drop down is too wide’ is closed to new replies.