Out of the box, WooCommerce displays the product category description only on the first page of the category archive. In other words, if the category contains a bunch of products and is paginated, the category description will not be shown on page 2, 3, etc.
But what if you want to display the category description on all the paginated pages? What if, for example, you are running a special promotion and want to include the promotion details in the category description and make sure your shop visitor sees it regardless of which page of the category s/he is on?
The solution is quite straight-forward. Add the following code to your theme’s functions.php
file:
/* Display WooCommerce product category description on all category archive pages */ function my_theme_woocommerce_taxonomy_archive_description() { if ( is_tax( array( 'product_cat', 'product_tag' ) ) && get_query_var( 'paged' ) != 0 ) { $description = wc_format_content( term_description() ); if ( $description ) { echo ' ' . $description . ' '; } } } add_action( 'woocommerce_archive_description', 'my_theme_woocommerce_taxonomy_archive_description');
The WooCommerce category pages’ layout is governed by the /templates/archive-product.php
template and we leverage the woocommerce_archive_description
action hook called in this template.
Our custom function above is almost a carbon copy of the default woocommerce_taxonomy_archive_description
function, with only one difference: instead of using get_query_var( 'paged' ) == 0
as in the default function, we use get_query_var( 'paged' ) != 0
.
This ensures that the category description is added on all the category pages. Since we do not override the default function, but merely hook into the woocommerce_archive_description
action, the category description is still added on the first category page by the default function.
Nicely done
Thanks, Vali, appreciated!
thank you!
My pleasure!
Hi!,
I am facing the same issue in shop page where shop description is showing in main page but not on paginations.
Any clues what to do here.
Hi Subrat,
I’m not entirely sure what you mean by “shop page” and “shop description”; could you please clarify? The blog post is about the product category description and the category pages.
Perfect! Thank you! Love your website!
Thank you very much for your kind words, Ashley, much appreciated!
Thank you!!!
You’re most welcome!
This is not working for me. website: http://www.shoppingandcoupon.com/
Hi, this works great and does indeed display on every paginated page, but I was wondering if you were able to help.
I added the following to my functions.php:
remove_action( ‘woocommerce_archive_description’, ‘woocommerce_taxonomy_archive_description’, 10 );
add_action( ‘woocommerce_after_shop_loop’, ‘woocommerce_taxonomy_archive_description’, 100 );
to get the category description to display at the bottom, which works fine, but when I add your code above, the first page works as normal with description underneath the products, but the description appears above th products again on the second and following pages.
Is there any way of combining the above and your code to allow every page to display the description to the bottom?
Thanks in advance, p.s. as you can probably tell I’m not a hard-core coder π
Hi Wayne,
Thanks for stopping by. I’m glad that you found the snippet useful.
Regarding your question, try this:
Notice that I removed the
get_query_var( 'paged' ) != 0
condition from theif
statement in the original version of the custom function. Since we want to display the category description on all pages (including the first one), we don’t need to check which page we’re on.I didn’t test this, but I think it should sort you out. Let me know how it goes.
Hey Mr Ninja. I am trying to display a category description when using the woocommerce element “Product categories” (Display product categories loop)
It displays by default the image, the name and the number of product inside that category. But not the description.
I can’t find the action to hook the function with
Hi Baudouin,
It’s a little bit difficult for me to give you an exact answer for this as I would need to see your code and learn more about the context you’re trying to display the category description in. That being said, the WooCommerce product categories are just a regular WordPress custom taxonomy, so you can use the WordPress
get_term()
orget_terms()
functions to retrieve the term data from the database (including the description). So something along these lines:See more here, for example.
I hope this helps to point you in the right direction.
Hey Mr Ninja,
Sorry I didn’t provide enough context. I am developing a website using wordpress with a theme named porto. Woocommerce comes as a plugin. I have as well a plugin named Visual composer. So when I created a new page (I do not like the default pages created by the theme and the way woocommerce pushes you to link the shop to a certain page) I added one of those “element” that you can find in the visual composer under the woocommerce category.
To do so, I created a row container, a custom column. Inside that column I added this Product category loops, and chose to display only 1 category. The theme give you the option (appearance) to display the thumb image, the name and the quantity of the product under that category. What I wanted was to display the description next to the thumb image.
What you gave me helped me understand where to look at!
What I did, I edited the content-product_cat.php (~/woocommerce/) and added the element from the class with $category->description.
But I think it’s not really convenient the change the code that way. So I wanted to find the action to hook my custom function with. And add the code in function.php
Anyway, it works now so I won’t complain.
I have been looking at your website and you profile, it is really great. The page looks fantastic, you story is source of inspiration! Plus you are helping people on your blog, with fast answer. You really are the ninja that internet deserve π
Take care!
Thank you for your kind words, much appreciated. It’s always heartwarming when somebody finds the blog useful.
Regarding your issue, I’m glad you figured it out. I don’t think the ‘WooCommerce Category’ is one of the default Visual Composer’s elements, so it must have been added by the theme. Hence the best way to change the output will depend on how the theme added the element in the first place. Overriding the element’s definition file in your child theme is a completely viable way. From what you wrote it sounds like that’s what you did (I hope you’re using a child theme and didn’t modify the file directly in the parent theme itself!). But you could also probably remove the added element and add it again using the Visual Composer API in your
functions.php
. Or create a brand new element that would do exactly what you want. As it’s often the case with WordPress, there are multiple ways to achieve the same result πYou are very Welcome.
Awesome, I didn’t think about creating my own vp element!
About the parent/child I am not sure ;/ I went into appearance, editor and under theme to edit (porto in my case) I found my php files.
So I am guessing that I actually edited the parent theme :/ Is that really bad? and why?
If you’re making any customizations to your site, you almost always want to use a child theme. The main issue with not using one is that when you update the parent theme (when the original developer releases a new patch or update), your modifications may be overwritten by the update and ultimately lost. Using a child theme ensures that your modifications are preserved and makes the theme update process much more straightforward.
There are other advantages as well and if you google around a little, you’ll find plenty of resources on child themes. This Smashing Magazine article is a good place to start.
Popular commercial themes often come with an easy-to-install child theme skeleton, so it’s easy to get started. I’m not 100% certain, but I think Porto has one too (it’d be part of the theme bundle).
Ok I didn’t know that.
I found the child theme, but I guess It’s a bit too late for my current website.
Thank you so much again for your help!
Hi Mr Ninja!
Today is the day I have to create a child theme I think
So Does that mean I’m gonna have to redo my entire website ? How can I do the transition to a child theme and then update the parent one ?
That really depends on the extent of modifications to the parent theme you made and how you made them. For example, if you edited some of the theme files directly, the migration to the child theme will be more involved than if you just configured the theme through the WordPress admin system. But overall you shouldn’t need to redo your entire site, only apply the same modifications and configuration to the child theme.
There are plenty of good tutorials online on setting up and using WordPress child themes, so I would suggest that you look some up and go through them carefully before you start working on the migration process. Oftentimes commercial themes come with a skeleton child theme and some documentation on how to use it – perhaps yours does as well – so that might help you too.
I’m sorry if this is a bit vague, but it’s a fairly wide topic, beyond the scope of a simple comment. Good luck!
Hi there, I’m using the Panoramic premium theme on my site and when I add the snippet, piece of code to the function.php nothing happens and no category or production description shows. Not sure why?
Hi Pheel,
Hmm, that sounds strange. I’m not familiar with the Panoramic theme, but I had a quick look at the free version and I don’t see anything in the theme’s code that should conflict with the snippet.
Two quick questions: (1) Before you added the snippet, did the category and product descriptions display fine? (2) When you insert the snippet and the category and product descriptions don’t show, does the rest of your site work ok?
Works like a charm, thanks!
Awesome, my pleasure!
Worked great to get the cat. descriptions on each of my paginated category pages, thank you.
Fantastic, I’m glad to hear that. You’re most welcome.
nice article
Thank you, Mahendra, much appreciated.
Warm and juicy THANK YOU!
My pleasure! I’m glad you found the post useful.
Hi
Thanks for writing this code but I have one query, As this code is working fine on Product Category, Can you please suggest something where I can also show description on on Product Attribute terms(collections) pagination?
Looking for some solution for that.
Thanks for providing code.
Hey there,
Could you give me a link to an example page? I’m not sure I fully understand what you mean since from the top of my head the product terms are just a filter on top of the product category pages (using the same product category templates), so the code should still apply.
Hi,
Thanks for your reply here is the link for the Product Attributes : https://goo.gl/b8RDGw Be Inspired & Search Dates supplied as a product description. If you go to page 2 then it won’t show Be Inspired & Search Dates
This one is for the product category https://goo.gl/CgmT4a while you’re going on product category page it’s showing description perfect even on page 2.
So, For the product category it’s working perfect but not for the product attributes.
Hello,
The website that you linked uses a custom theme which often changes the way the different pages are generated and what works with with default theme (and WooCommerce) installation may no longer apply.
With that being said, I had a look at the source code of the site and I think that if you slightly modify the
if
statement of the shortcode, it should work with the collection pages. Try changing it to the following (notice the added custom taxonomy in the array):if ( is_tax( array( 'product_cat', 'product_tag', 'pa_collections' ) ) && get_query_var( 'paged' ) != 0 ) {
From what I can tell, the collection pages on your website are generated using a custom taxonomy (
'pa_collections'
) which is why just using the default WooCommerce taxonomies ('product_cat'
and'product_tag'
) in theif
statement isn’t sufficient.What the
if
statement in the original shortcode does is detect whether we’re on a product category or a product tag archive and if so, it adds the category description in the page header. If the page is generated using a different taxonomy, theif
statement will evaluate as false and the description will not display. By adding your custom taxonomy into the array, theif
statement should evaluate to true on the collection pages and correctly display the description.Give it a shot and see how it goes.
Hi Richard
Thank you for the suggestion Actually I forgot to try using that kind of custom taxonomy ‘pa_collections’ works.
Thanks for reference and code.
Great, I’m glad to hear it was helpful!
Thank you so much!!!
You’re welcome, Andres. I’m glad you found the post helpful.
I have used the code below to display my category description below my products. I would like the category name (CBD) to be displayed at the top of the page while keeping the category descriptions below the product. Thanks for any and all help.
remove_action( ‘woocommerce_archive_description’, ‘woocommerce_taxonomy_archive_description’, 10 );
add_action( ‘woocommerce_after_main_content’, ‘woocommerce_taxonomy_archive_description’, 100 );
add_action( ‘woocommerce_after_shop_loop’, ‘woocommerce_taxonomy_archive_description’, 100 );
Hi Jana,
Thanks for stopping by. What you can do is 1) remove the default taxonomy archive description like you did, and 2) hook into the same action hook with a lower priority your custom function that will display just the category title. So it could look something like this:
You’ll have to play with the custom function and see if that works. It’s from the top of my head and I haven’t tested it. But that’s the gist of it.
By the way, this is quite a helpful post series that lets you quickly see the different available WooCommerce hooks and their position on the page: https://businessbloomer.com/woocommerce-visual-hook-guide-archiveshopcat-page/.
I hope this helps.
hi,
how to remove p tags from category description woocommerce
thanks
I’m sorry, I don’t know from the top of my head, I’d have to test it. But try
remove_filter('woocommerce_short_description', 'wpautop');
and see if that works. It may remove thetags elsewhere too, though.
Alternatively, try looking up the
wc_format_content()
function which is what WooCommerce uses to format the description before displaying it in the page and see if there’s some filter that you could use.You could also write a custom function that hooks into the
woocommerce_archive_description
hook like I did in this post and remove thetags in it with string replace or regex.
not work “remove_filter(‘term_description’,’wpautop’);”
thanks so much it works great
remove_filter(‘woocommerce_short_description’, ‘wpautop’);
best regards
Fantastic. I’m glad it worked. Thanks for reporting back π
Hi Richard,
Love your site and easy manner in working with people. Kudos!
I used the code left for a different Wayne to remove the category description from the top of the page to the bottom on all of the pages and it works except when the bottom row of products isnβt full. If the last row of products has one or two items empty spaces the description takes up one or both spaces instead of below all products. Can you help me fix this issue?
Thanksβ Wayne S.
Hi Wayne,
Thank you very much for your kind words.
I checked your site and it happens because the product elements are floated, so the category description element takes up the free space right after them (if there’s any left) instead of stacking underneath as a block. You’ll need to clear the float from the products. Try adding this to your theme’s CSS file:
It should fix the issue.
Worked perfectly! Thanks for the quick response.
Great! I’m glad it worked π
Quick follow up on moving the description to the bottom of the Woocommerce Shop page after all of the product rows. I assume there is a tweak that can be made to the code you provided already but I’m not sure what it is. Also, will the CSS to move the description to a new line following the products work for this move as well?
I’m sorry, I’m not completely clear on what you’re asking about. Could you elaborate? Based on your previous comment and on what I saw when I checked your website last time, the code already worked for you to move the category description under all the products and the CSS snippet I gave you last time should display it as a block in a new row.
Thank you
You’re welcome!
Lifesaver π
Saving lives one custom function at a time π
thans alot
You’re welcome!
Struggling to get this to work, am pasting code into my functions.php of my child theme but does’t show description copy/text. Also tried posting in the main theme functions.php and still does;t work.
Where in the functions.php does the code need to be pasted.
Hi Benn,
Thanks for stopping by.
It sounds like you are doing it right, but ultimately it all depends on how your theme and site are structured. I had a quick look at your site and it seems that it might be using WP Bakery to implement the pages. If that is indeed the case and the WooCommerce category pages are set up with the WP Bakery page builder rather than leveraging the standard WooCommerce templates, the snippet might not work and the category description would need to be added in some other way. Unfortunately that is not something I can provide a solution from the top of my head. I would need to have a closer look at the site and the theme.
Hi,
First of all, thank you for this great article.
My web site: https://www.caglayansuaritma.com.tr
And this code works on category pages.
For Example: https://www.caglayansuaritma.com.tr/sanayi-tipi-su-aritma-cihazlari/page/2/
But it doesn’t work on the main store page. It only works on the first page.
For example: https://www.caglayansuaritma.com.tr/su-aritma-cihazlari/page/2/ and other pages.
My Main Store Page: https://www.caglayansuaritma.com.tr/su-aritma-cihazlari/
How should I edit this code to run on the main store page?
Best Regards,
Hi there,
If I understand your question correctly, I think the issue is that the code snippet from my blog post is meant to add the WooCommerce category description on the category archive pages. However, the main store page does not display a single category. Instead it shows products from all the different categories. So technically there is no way for the template to determine which category description should be displayed on the main store page.
That being said, you should be able to add content to the main store page by editing it in your WordPress admin. In other words, the main store page will not display a category description, but it will display the store page content directly.
I hope that helps.
How does this affect SEO? Lets say its just a standard keyword rich description?
Lets say a user is using YOAST SEO Plugin and enters the canonical url for a category to be its own url (i.e. referencing itself). That means page 1 is referencing itself… page 2 references page 1 as normal for canonicals.
With the above in mind would you suggest or NOT suggest doing this fix to show description on all pages as standard? I understand the use case you used for “offers” as an example. Just concerned how this affects SEO moving forward. In theory the canonical should stop any detrimental Search Engine results due to canonical being setup, but as you say, lots of benefits in terms of the customer journey.
Hi Nick,
Personally I doubt this would have any impact on SEO. Search engines are smart enough to figure out it’s paginated content when crawling the site. Plus there will likely already be other elements on the page that will be shared across the pages and may use a more critical HTML tag such as
h1
or similar.Google actually recommends against making the first page canonical. From Google docs: “Don’t use the first page of a paginated sequence as the canonical page. Instead, give each page its own canonical URL.”
If you think about it, it makes sense. Page 2 is not a duplicate of page 1 even if some elements on the pages are the same or similar. Ultimately the pages are showing different products and those make up majority of the content on the page.
Yoast SEO has built-in features to help search engines recognize paginated content, see here for reference. So I’d just make sure that your site utilizes those and I think you should be good.
I hope this helps!