I recently had a customer that wanted a custom message across the top of the single product page but for only one product category. I put this text at the top of the category page, but she also wanted it displayed after they clicked on the individual products. To accomplish this, I added the code below to my functions.php file.
Note that if you want it displayed for all categories, you can remove the “if” line and the last bracket.
In this case, my category ID was 217, but you should change this to whatever your category ID is.
function add_custom_text_before_product_title() { if (has_term(217, 'product_cat')) { echo 'Custom text here'; } }
Of course, always make changes through FTP or your hosting file manager and make backups of your original files. Small coding errors in your functions.php file can take down your entire site.
Hope this helps!
Leave a Reply