Last active
April 4, 2024 05:53
-
-
Save mohsinworld/28c3d2c98dbcb2033d9651fd527e916b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Code Snippet | |
// Automatically shortens WooCommerce product titles on the main shop, category, and tag pages | |
// to a set number of characters | |
function short_woocommerce_product_titles_chars( $title, $id ) { | |
if ( ( is_shop() || is_product_tag() || is_product_category() ) && get_post_type( $id ) === 'product' ) { | |
// Kicks in if the product title is longer than 60 characters | |
if ( strlen( $title ) > 40) { | |
// Shortens it to 60 characters and adds ellipsis at the end | |
return substr( $title, 0, 40 ) . '...'; | |
} | |
} | |
return $title; | |
} | |
add_filter( 'the_title', 'short_woocommerce_product_titles_chars', 10, 2 ); | |
============================================================= | |
Custom CSS | |
.woocommerce-loop-product__title { | |
overflow: hidden; | |
display: -webkit-box; | |
-webkit-box-orient: vertical; | |
-webkit-line-clamp: 2; | |
} | |
============================================================= | |
Another way for Astra floating add to cart | |
.ast-sticky-add-to-cart-title {white-space:pre; overflow:hidden; text-overflow:ellipsis; width:660px;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment