How to Limit WooCommerce Product Titles
|
/ Documentation /Custom Code Snippets/WooCommerce Filters/ How to Limit WooCommerce Product Titles

How to Limit WooCommerce Product Titles

If your product titles are getting too long and messy on your website, you can make them shorter with a simple snippet of code. This can be particularly useful for maintaining a clean and concise product grid layout.

In this document, we’ll guide you through the process of how to limit WooCommerce product titles.

How to Limit WooCommerce Product Titles

Before we get started, make sure you have access to your WordPress admin dashboard. Then, you can follow the below attached step-by-step guide to limit WooCommerce Product Titles.

  • Log in to your WordPress admin panel.
  • Navigate to “Appearance” and click on “Theme Editor.”
  • On the right side, you’ll see a list of theme files. Look for your Astra Child Theme’s functions.php file. It should be located in the theme’s directory.
  • Click on the “functions.php” file to open it for editing.
  • Once you have the functions.php file open, you can add the following code snippet at the end of the file.
// Limit WooCommerce product titles​​
function astra_limit_woocommerce_product_title($title, $id = null) {
    $limit = 40; // Set the character limit you prefer
    if (strlen($title) > $limit) {
        $title = substr($title, 0, $limit) . '...';
    }
    return $title;
}
add_filter('the_title', 'astra_limit_woocommerce_product_title', 10, 2);
  • After adding the code snippet, make sure to save your changes. Simply click the “Update File” button at the bottom of the editing window.

You can customize the character limit by modifying the `$limit` variable within the code. Simply change the number in the `$limit = 40;` line to your preferred character count.

After adding the code snippet, visit your WooCommerce product pages to see the modified product titles with the character limit in effect.

Hope this document helped you understand how to limit WooCommerce Product Titles. If you need help, we’re just a message away.

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
On this page

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

This field is required.

REWIND

YEAR IN REVIEW

Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form