کوتاه کردن متن ها در تایتل ووکامرس

harbiline

Edris
دوستان راه حلی دارید ک به صورت خودکار متن ها در تایتل محصولات کوتاه بشه؟
adad-Untitled.png


مث عکسی ک دادم به صورت خودکار خودش کوتاه بشه مثلا بهش بگم تا 25 حرف مجازی بعداز اون بنویسه ادامه مطلب یا ... اینجوری؟!!؟؟؟

 

Alaric

کاربر عضو
من اینو سرچ کردم پیدا کردم ولی خودم تست نکردم

کد:
https://businessbloomer.com/woocommerce-shorten-product-titles/
Option 1 (CSS): Limit all WooCommerce product titles to one line only​

کد:
// Note: this is simple CSS that can be placed in your custom.css file
// This CSS also adds 3 dots ... at the end of each product title
 .woocommerce ul.products li.product h3 {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
Option 2 (PHP): Limit all WooCommerce product titles to max number of characters​

کد:
// Note: this is simple PHP that can be placed in your functions.php file
// Note: substr may give you problems, please check Option 3
add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 );
function shorten_woo_product_title( $title, $id ) {
if ( is_shop() && get_post_type( $id ) === 'product' ) {
return substr( $title, 0, 15 ); // change last number to the number of characters you want
} else {
return $title;
}
}
Option 3 (PHP): Limit all WooCommerce product titles to max number of words​

کد:
function shorten_woo_product_title( $title, $id ) {
if ( is_shop() && get_post_type( $id ) === 'product' ) {
return wp_trim_words( $title, 4 ); // change last number to the number of WORDS you want
} else {
return $title;
}
}
 
آخرین ویرایش توسط مدیر:

harbiline

Edris
پیداش کردم خودم

اینو تو فانکشن قالبتون بذارید حل میشه

کد:
add_filter( 'the_title', 'shorten_my_title', 10, 2 );

function shorten_my_title( $title, $id ) {
        if ( ! is_single() && get_post_type( $id ) === 'product' && strlen( $title ) > 24 ) {
                return substr( $title, 0, 24 ) . '...'; // change 50 to the number of characters you want to show
        } else {
                return $title;
        }
}
 

Alaric

کاربر عضو
تقربیا فایده ای نداشتش
با سلام من تست کردم کار کرد. تنها تفاوتش اینه که باید شما کلاس دقیق عنوان محصول رو بهش بدی

// Note: this is simple CSS that can be placed in your custom.css file
// This CSS also adds 3 dots ... at the end of each product title
.woocommerce ul.products li.product h3 {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}


تو اینجا کلاس معرفی شده  .woocommerce ul.products li.product h3 هستش. من تو پوسته اکسترا یک محصولا اضافه کردم و دیدم کلاس عناون محصول این هستش .woocommerce ul.products li.product .product-wrapper h3, .woocommerce-page ul.products li.product .product-wrapper h3 پس به این حالت تغییرش دادم.

.woocommerce ul.products li.product .product-wrapper h3, .woocommerce-page ul.products li.product .product-wrapper h3{
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}


شما هم از هر پوسته ای استفاده می کنی باید اینسپکت المنت بگیری ببینی کلاس پوسته محصولش چی هست.

اینم تصویر

You must be registered for see images attach


You must be registered for see images attach


 
بالا