WordPress.org

Forums

Category widgets Drop down is too wide (6 posts)

  1. laurakshank
    Member
    Posted 3 years ago #

    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="http://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?

  2. vtxyzzy
    Member
    Posted 3 years ago #

    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');
  3. laurakshank
    Member
    Posted 3 years ago #

    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

  4. vtxyzzy
    Member
    Posted 3 years ago #

    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.

  5. laurakshank
    Member
    Posted 3 years ago #

    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!

  6. laurakshank
    Member
    Posted 3 years ago #

    This worked perfectly - Thanks!!!

Topic Closed

This topic has been closed to new replies.

About this Topic