• Resolved abfchgirlx

    (@abfchgirlx)


    Hi There,

    I’m using the widget “WooCommerce Products” on my home page and I need to shorten the titles.

    I’ve been able to successfully shorten the titles on my shop page using this code;

    add_filter( 'the_title', 'shorten_my_title', 10, 2 );
    
    function shorten_my_title( $title, $id ) {
    	if ( is_shop() && get_post_type( $id ) === 'product' ) {
    		return substr( $title, 0, 50 ); // change 50 to the number of characters you want to show
    	} else {
    		return $title;
    	}
    }

    But since I’m working with products that are being listed due to a widget, the same function doesn’t work if I replace “shop” with “home.” Any suggestions?

    https://wordpress.org/plugins/woocommerce/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter abfchgirlx

    (@abfchgirlx)

    I did contact woocommerce themes directly and they suggested I use “widget_title” instead of “the_title” and there was no results either.

    Thread Starter abfchgirlx

    (@abfchgirlx)

    I ended up installing a plugin that does this for me. Resolved.

    Hi

    Can you share the link of the plugin for the same? I required the plugin for my site as well, I have used the code you have mentioned above but that did not work for me? I am using mystile theme.

    Hi abfchgirlx

    Can you please help me with the plugin name. I am still struggling with the same issue. Code you have mentioned above did not work for me.

    Thread Starter abfchgirlx

    (@abfchgirlx)

    I’m sorry, I got distracted and forgot you asked. 🙂

    Honestly, I can’t remember. I worked on this websites for days and long hours and did many things to get it to function correctly. I remember having to disable plugins because they conflicted, and some didn’t work 100% on all the pages. I also deleted the ones I don’t need. But I know CSS can also do what we want. I can’t tell you my reason why I resorted to the CSS since I used the plugin, but the code I’m using now is;

    .home .woocommerce ul.product_list_widget li a {
        font-size: 1em;
        margin: 0;
        overflow: hidden;
        padding: 0.5em 0;
        text-overflow: ellipsis;
        white-space: nowrap;

    That’s just an example of my css. You can see the rest of it at fallfordesign.com (using firebug). 🙂

    Hi abfchgirlx

    You are a star.
    I have spend my hours and hours searching for the same.
    This really worked for me. Just for anyone else’s reference I am adding below code for the shop page. Code you have given is home page.

    .woocommerce-page ul.products li.product h3 {
    font-size: 1em;
    margin: 0;
    overflow: hidden;
    padding: 0.5em 0;
    text-overflow: ellipsis;
    white-space: nowrap;
    }

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WooCommerce Product Widget, Limit Product Titles on Home Page’ is closed to new replies.