Shorten product titles on Woocommerce archive pages











up vote
1
down vote

favorite












I found this code to limit woocommerce product title and its working. But the problem is it applies everywhere even in single product page. How do I make exception not to apply in product page?



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









share|improve this question




























    up vote
    1
    down vote

    favorite












    I found this code to limit woocommerce product title and its working. But the problem is it applies everywhere even in single product page. How do I make exception not to apply in product page?



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









    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I found this code to limit woocommerce product title and its working. But the problem is it applies everywhere even in single product page. How do I make exception not to apply in product page?



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









      share|improve this question















      I found this code to limit woocommerce product title and its working. But the problem is it applies everywhere even in single product page. How do I make exception not to apply in product page?



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






      php wordpress woocommerce product title






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 22:15









      LoicTheAztec

      78.3k125992




      78.3k125992










      asked Nov 10 at 13:49









      Rifat Rahman

      113




      113
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          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;
          }
          }





          share|improve this answer










          New contributor




          Alex Vasilyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • Thank you :) Its works
            – Rifat Rahman
            Nov 11 at 19:00










          • this code also applied in the backend otherwise its working good. Admin Panel >> Products >> All Products imgur.com/a/GrIMKow
            – Rifat Rahman
            2 days ago


















          up vote
          0
          down vote













          The best way is to use woocommerce_shop_loop_item_title hook:




          • First unhooking the product title from loop archive pages.

          • Then hooking back a custom version that shorten the title as you want.


          This way this shortening will be applied exclusively on product titles on all woocommerce loops (all woocommerce archives pages, related products, upsells, cross sells, shortcodes, widgets…) avoiding changes with single product title.



          remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
          add_action( 'woocommerce_shop_loop_item_title', 'shorten_loop_product_title', 10 );
          function shorten_loop_product_title() {
          echo '<h2 class="woocommerce-loop-product__title">' . wp_trim_words( get_the_title(), 4, '...' ) . '</h2>';
          }


          Code goes in function.php file of your active child theme (active theme). Tested and works.



          To shorten product title limiting the number of characters with PHP substr() function, replace the following line in my code:



          echo '<h2 class="woocommerce-loop-product__title">' . wp_trim_words( get_the_title(), 4, '...' ) . '</h2>';


          by:



          echo '<h2 class="woocommerce-loop-product__title">' . substr( get_the_title(), 0, 25 ) . '...' . '</h2>';




          If you want this to be applied only on woocommerce archives pages as shop, you will use:



          remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
          add_action( 'woocommerce_shop_loop_item_title', 'shorten_loop_product_title', 10 );
          function shorten_loop_product_title() {
          echo '<h2 class="woocommerce-loop-product__title">';

          if ( is_shop() || is_product_category() || is_product_tag() ) {
          echo wp_trim_words( get_the_title(), 4, '...' );
          } else {
          echo get_the_title();
          }

          echo '</h2>';
          }


          Code goes in function.php file of your active child theme (active theme). Tested and works.



          To shorten product title limiting the number of characters with PHP substr() function, replace the following line in my code:



          echo wp_trim_words( get_the_title(), 4, '...' );


          by:



          echo substr( get_the_title(), 0, 25 ) . '...';




          Addition related to your comment



          To shorten product title mimiting the number of characters with PHP substr() function, replace:






          share|improve this answer























          • Thanks I'm using this code which is working fine to set the limit except product page. How do I set character limit if I want to your code? // Set title limit without products page add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 ); function shorten_woo_product_title( $title, $id ) { if ( ! is_single( $id ) && get_post_type( $id ) === 'product' ) { return substr( $title, 0, 25 ).'...'; // change last number to the number of words you want } else { return $title; } }
            – Rifat Rahman
            Nov 11 at 18:58












          • @RifatRahman I have added an update at the end related to your comment… Have you tried it? If this answer answers your question, you could please accept the answer, Thank you.
            – LoicTheAztec
            16 hours ago











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239620%2fshorten-product-titles-on-woocommerce-archive-pages%23new-answer', 'question_page');
          }
          );

          Post as a guest
































          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          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;
          }
          }





          share|improve this answer










          New contributor




          Alex Vasilyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • Thank you :) Its works
            – Rifat Rahman
            Nov 11 at 19:00










          • this code also applied in the backend otherwise its working good. Admin Panel >> Products >> All Products imgur.com/a/GrIMKow
            – Rifat Rahman
            2 days ago















          up vote
          0
          down vote













          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;
          }
          }





          share|improve this answer










          New contributor




          Alex Vasilyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • Thank you :) Its works
            – Rifat Rahman
            Nov 11 at 19:00










          • this code also applied in the backend otherwise its working good. Admin Panel >> Products >> All Products imgur.com/a/GrIMKow
            – Rifat Rahman
            2 days ago













          up vote
          0
          down vote










          up vote
          0
          down vote









          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;
          }
          }





          share|improve this answer










          New contributor




          Alex Vasilyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          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;
          }
          }






          share|improve this answer










          New contributor




          Alex Vasilyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer








          edited Nov 10 at 14:43





















          New contributor




          Alex Vasilyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered Nov 10 at 14:28









          Alex Vasilyev

          993




          993




          New contributor




          Alex Vasilyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Alex Vasilyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Alex Vasilyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.












          • Thank you :) Its works
            – Rifat Rahman
            Nov 11 at 19:00










          • this code also applied in the backend otherwise its working good. Admin Panel >> Products >> All Products imgur.com/a/GrIMKow
            – Rifat Rahman
            2 days ago


















          • Thank you :) Its works
            – Rifat Rahman
            Nov 11 at 19:00










          • this code also applied in the backend otherwise its working good. Admin Panel >> Products >> All Products imgur.com/a/GrIMKow
            – Rifat Rahman
            2 days ago
















          Thank you :) Its works
          – Rifat Rahman
          Nov 11 at 19:00




          Thank you :) Its works
          – Rifat Rahman
          Nov 11 at 19:00












          this code also applied in the backend otherwise its working good. Admin Panel >> Products >> All Products imgur.com/a/GrIMKow
          – Rifat Rahman
          2 days ago




          this code also applied in the backend otherwise its working good. Admin Panel >> Products >> All Products imgur.com/a/GrIMKow
          – Rifat Rahman
          2 days ago












          up vote
          0
          down vote













          The best way is to use woocommerce_shop_loop_item_title hook:




          • First unhooking the product title from loop archive pages.

          • Then hooking back a custom version that shorten the title as you want.


          This way this shortening will be applied exclusively on product titles on all woocommerce loops (all woocommerce archives pages, related products, upsells, cross sells, shortcodes, widgets…) avoiding changes with single product title.



          remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
          add_action( 'woocommerce_shop_loop_item_title', 'shorten_loop_product_title', 10 );
          function shorten_loop_product_title() {
          echo '<h2 class="woocommerce-loop-product__title">' . wp_trim_words( get_the_title(), 4, '...' ) . '</h2>';
          }


          Code goes in function.php file of your active child theme (active theme). Tested and works.



          To shorten product title limiting the number of characters with PHP substr() function, replace the following line in my code:



          echo '<h2 class="woocommerce-loop-product__title">' . wp_trim_words( get_the_title(), 4, '...' ) . '</h2>';


          by:



          echo '<h2 class="woocommerce-loop-product__title">' . substr( get_the_title(), 0, 25 ) . '...' . '</h2>';




          If you want this to be applied only on woocommerce archives pages as shop, you will use:



          remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
          add_action( 'woocommerce_shop_loop_item_title', 'shorten_loop_product_title', 10 );
          function shorten_loop_product_title() {
          echo '<h2 class="woocommerce-loop-product__title">';

          if ( is_shop() || is_product_category() || is_product_tag() ) {
          echo wp_trim_words( get_the_title(), 4, '...' );
          } else {
          echo get_the_title();
          }

          echo '</h2>';
          }


          Code goes in function.php file of your active child theme (active theme). Tested and works.



          To shorten product title limiting the number of characters with PHP substr() function, replace the following line in my code:



          echo wp_trim_words( get_the_title(), 4, '...' );


          by:



          echo substr( get_the_title(), 0, 25 ) . '...';




          Addition related to your comment



          To shorten product title mimiting the number of characters with PHP substr() function, replace:






          share|improve this answer























          • Thanks I'm using this code which is working fine to set the limit except product page. How do I set character limit if I want to your code? // Set title limit without products page add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 ); function shorten_woo_product_title( $title, $id ) { if ( ! is_single( $id ) && get_post_type( $id ) === 'product' ) { return substr( $title, 0, 25 ).'...'; // change last number to the number of words you want } else { return $title; } }
            – Rifat Rahman
            Nov 11 at 18:58












          • @RifatRahman I have added an update at the end related to your comment… Have you tried it? If this answer answers your question, you could please accept the answer, Thank you.
            – LoicTheAztec
            16 hours ago















          up vote
          0
          down vote













          The best way is to use woocommerce_shop_loop_item_title hook:




          • First unhooking the product title from loop archive pages.

          • Then hooking back a custom version that shorten the title as you want.


          This way this shortening will be applied exclusively on product titles on all woocommerce loops (all woocommerce archives pages, related products, upsells, cross sells, shortcodes, widgets…) avoiding changes with single product title.



          remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
          add_action( 'woocommerce_shop_loop_item_title', 'shorten_loop_product_title', 10 );
          function shorten_loop_product_title() {
          echo '<h2 class="woocommerce-loop-product__title">' . wp_trim_words( get_the_title(), 4, '...' ) . '</h2>';
          }


          Code goes in function.php file of your active child theme (active theme). Tested and works.



          To shorten product title limiting the number of characters with PHP substr() function, replace the following line in my code:



          echo '<h2 class="woocommerce-loop-product__title">' . wp_trim_words( get_the_title(), 4, '...' ) . '</h2>';


          by:



          echo '<h2 class="woocommerce-loop-product__title">' . substr( get_the_title(), 0, 25 ) . '...' . '</h2>';




          If you want this to be applied only on woocommerce archives pages as shop, you will use:



          remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
          add_action( 'woocommerce_shop_loop_item_title', 'shorten_loop_product_title', 10 );
          function shorten_loop_product_title() {
          echo '<h2 class="woocommerce-loop-product__title">';

          if ( is_shop() || is_product_category() || is_product_tag() ) {
          echo wp_trim_words( get_the_title(), 4, '...' );
          } else {
          echo get_the_title();
          }

          echo '</h2>';
          }


          Code goes in function.php file of your active child theme (active theme). Tested and works.



          To shorten product title limiting the number of characters with PHP substr() function, replace the following line in my code:



          echo wp_trim_words( get_the_title(), 4, '...' );


          by:



          echo substr( get_the_title(), 0, 25 ) . '...';




          Addition related to your comment



          To shorten product title mimiting the number of characters with PHP substr() function, replace:






          share|improve this answer























          • Thanks I'm using this code which is working fine to set the limit except product page. How do I set character limit if I want to your code? // Set title limit without products page add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 ); function shorten_woo_product_title( $title, $id ) { if ( ! is_single( $id ) && get_post_type( $id ) === 'product' ) { return substr( $title, 0, 25 ).'...'; // change last number to the number of words you want } else { return $title; } }
            – Rifat Rahman
            Nov 11 at 18:58












          • @RifatRahman I have added an update at the end related to your comment… Have you tried it? If this answer answers your question, you could please accept the answer, Thank you.
            – LoicTheAztec
            16 hours ago













          up vote
          0
          down vote










          up vote
          0
          down vote









          The best way is to use woocommerce_shop_loop_item_title hook:




          • First unhooking the product title from loop archive pages.

          • Then hooking back a custom version that shorten the title as you want.


          This way this shortening will be applied exclusively on product titles on all woocommerce loops (all woocommerce archives pages, related products, upsells, cross sells, shortcodes, widgets…) avoiding changes with single product title.



          remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
          add_action( 'woocommerce_shop_loop_item_title', 'shorten_loop_product_title', 10 );
          function shorten_loop_product_title() {
          echo '<h2 class="woocommerce-loop-product__title">' . wp_trim_words( get_the_title(), 4, '...' ) . '</h2>';
          }


          Code goes in function.php file of your active child theme (active theme). Tested and works.



          To shorten product title limiting the number of characters with PHP substr() function, replace the following line in my code:



          echo '<h2 class="woocommerce-loop-product__title">' . wp_trim_words( get_the_title(), 4, '...' ) . '</h2>';


          by:



          echo '<h2 class="woocommerce-loop-product__title">' . substr( get_the_title(), 0, 25 ) . '...' . '</h2>';




          If you want this to be applied only on woocommerce archives pages as shop, you will use:



          remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
          add_action( 'woocommerce_shop_loop_item_title', 'shorten_loop_product_title', 10 );
          function shorten_loop_product_title() {
          echo '<h2 class="woocommerce-loop-product__title">';

          if ( is_shop() || is_product_category() || is_product_tag() ) {
          echo wp_trim_words( get_the_title(), 4, '...' );
          } else {
          echo get_the_title();
          }

          echo '</h2>';
          }


          Code goes in function.php file of your active child theme (active theme). Tested and works.



          To shorten product title limiting the number of characters with PHP substr() function, replace the following line in my code:



          echo wp_trim_words( get_the_title(), 4, '...' );


          by:



          echo substr( get_the_title(), 0, 25 ) . '...';




          Addition related to your comment



          To shorten product title mimiting the number of characters with PHP substr() function, replace:






          share|improve this answer














          The best way is to use woocommerce_shop_loop_item_title hook:




          • First unhooking the product title from loop archive pages.

          • Then hooking back a custom version that shorten the title as you want.


          This way this shortening will be applied exclusively on product titles on all woocommerce loops (all woocommerce archives pages, related products, upsells, cross sells, shortcodes, widgets…) avoiding changes with single product title.



          remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
          add_action( 'woocommerce_shop_loop_item_title', 'shorten_loop_product_title', 10 );
          function shorten_loop_product_title() {
          echo '<h2 class="woocommerce-loop-product__title">' . wp_trim_words( get_the_title(), 4, '...' ) . '</h2>';
          }


          Code goes in function.php file of your active child theme (active theme). Tested and works.



          To shorten product title limiting the number of characters with PHP substr() function, replace the following line in my code:



          echo '<h2 class="woocommerce-loop-product__title">' . wp_trim_words( get_the_title(), 4, '...' ) . '</h2>';


          by:



          echo '<h2 class="woocommerce-loop-product__title">' . substr( get_the_title(), 0, 25 ) . '...' . '</h2>';




          If you want this to be applied only on woocommerce archives pages as shop, you will use:



          remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
          add_action( 'woocommerce_shop_loop_item_title', 'shorten_loop_product_title', 10 );
          function shorten_loop_product_title() {
          echo '<h2 class="woocommerce-loop-product__title">';

          if ( is_shop() || is_product_category() || is_product_tag() ) {
          echo wp_trim_words( get_the_title(), 4, '...' );
          } else {
          echo get_the_title();
          }

          echo '</h2>';
          }


          Code goes in function.php file of your active child theme (active theme). Tested and works.



          To shorten product title limiting the number of characters with PHP substr() function, replace the following line in my code:



          echo wp_trim_words( get_the_title(), 4, '...' );


          by:



          echo substr( get_the_title(), 0, 25 ) . '...';




          Addition related to your comment



          To shorten product title mimiting the number of characters with PHP substr() function, replace:







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 11 at 21:01

























          answered Nov 10 at 22:13









          LoicTheAztec

          78.3k125992




          78.3k125992












          • Thanks I'm using this code which is working fine to set the limit except product page. How do I set character limit if I want to your code? // Set title limit without products page add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 ); function shorten_woo_product_title( $title, $id ) { if ( ! is_single( $id ) && get_post_type( $id ) === 'product' ) { return substr( $title, 0, 25 ).'...'; // change last number to the number of words you want } else { return $title; } }
            – Rifat Rahman
            Nov 11 at 18:58












          • @RifatRahman I have added an update at the end related to your comment… Have you tried it? If this answer answers your question, you could please accept the answer, Thank you.
            – LoicTheAztec
            16 hours ago


















          • Thanks I'm using this code which is working fine to set the limit except product page. How do I set character limit if I want to your code? // Set title limit without products page add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 ); function shorten_woo_product_title( $title, $id ) { if ( ! is_single( $id ) && get_post_type( $id ) === 'product' ) { return substr( $title, 0, 25 ).'...'; // change last number to the number of words you want } else { return $title; } }
            – Rifat Rahman
            Nov 11 at 18:58












          • @RifatRahman I have added an update at the end related to your comment… Have you tried it? If this answer answers your question, you could please accept the answer, Thank you.
            – LoicTheAztec
            16 hours ago
















          Thanks I'm using this code which is working fine to set the limit except product page. How do I set character limit if I want to your code? // Set title limit without products page add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 ); function shorten_woo_product_title( $title, $id ) { if ( ! is_single( $id ) && get_post_type( $id ) === 'product' ) { return substr( $title, 0, 25 ).'...'; // change last number to the number of words you want } else { return $title; } }
          – Rifat Rahman
          Nov 11 at 18:58






          Thanks I'm using this code which is working fine to set the limit except product page. How do I set character limit if I want to your code? // Set title limit without products page add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 ); function shorten_woo_product_title( $title, $id ) { if ( ! is_single( $id ) && get_post_type( $id ) === 'product' ) { return substr( $title, 0, 25 ).'...'; // change last number to the number of words you want } else { return $title; } }
          – Rifat Rahman
          Nov 11 at 18:58














          @RifatRahman I have added an update at the end related to your comment… Have you tried it? If this answer answers your question, you could please accept the answer, Thank you.
          – LoicTheAztec
          16 hours ago




          @RifatRahman I have added an update at the end related to your comment… Have you tried it? If this answer answers your question, you could please accept the answer, Thank you.
          – LoicTheAztec
          16 hours ago


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239620%2fshorten-product-titles-on-woocommerce-archive-pages%23new-answer', 'question_page');
          }
          );

          Post as a guest




















































































          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation