1

On WooCommerce admin Products List, all products are listed, but the product Name / Title is shortened, with an ellipse at the end...

I have searched all over how to make the product title showing in full but without any success, I can change it on the front end but not in the admin dashboard at all.

add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 );
function shorten_woo_product_title( $title, $id ) {
    if ( ! is_singular( array( 'product' ) ) && get_post_type( $id ) === 'product' ) {
        return wp_trim_words( $title, 4, '...' ); // change last number to the number of words you want
    } else {
        return $title;
    }
}

Now this changes the product name in the front end, but it's still shortened on the admin products list. I need to show it full Title/Name in admin side.

This answer also shows how to change it on the front end:

I am using WordPress 6.2.2 and WooCommerce 7.8.0


UPDATE

Screenshot of the Problem:

enter image description here

Actually, you don't know what you are editing until you go into the product. This is the main reason I would like to have the title / Name in full.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Gamo SA
  • 11
  • 3

1 Answers1

0

To avoid the product title to be shortened in Admin products list, you just need to use is_admin() conditional function on your IF statement as an additional condition like:

add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 );
function shorten_woo_product_title( $title, $id ) {
    if ( ! is_admin() && ! is_singular( array( 'product' ) ) && get_post_type( $id ) === 'product' ) {
        $title = wp_trim_words( $title, 4, '...' ); // change last number to the number of words you want
    }
    return $title;
}

This will avoid any changes for Product titles in the backend.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • As this answer works and answer your question, could you please accept this answer (To mark an answer as accepted, click on the check mark beside the answer to toggle it from greyed out to filled in), thank you. – LoicTheAztec Jun 21 '23 at 03:27