Not apply functions.php changes to a specific element
-
Hi,
I am working with Woocommerce and Flatsome Theme.
I recently added this code to my functions.php file, in order to have H2 tags on my products titles in category pages :
function woocommerce_template_loop_product_title() { echo '<h2 class="h4"><a href="'.get_the_permalink().'">' . get_the_title() . '</a></h2>'; }However, I use the same function to display products in my mega menu, and I don’t want them to have h2 tags.
Thus I would like to exclude those specific products on the previous code. They are defined by a CSS ID when they are in the menu. But I don’t know how to say “apply this change to everything except those elements” in PHP.
I really need your help.
Thanks in advance.
Julien
-
This topic was modified 5 years, 5 months ago by
zelph14.
-
This topic was modified 5 years, 5 months ago by
-
HI you can easily do it by unhook that function. and then add action your custom function .You can use my code
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 ); add_action( 'woocommerce_shop_loop_item_title', 'my_template_loop_product_title', 10 ); function my_template_loop_product_title() { echo '<h2 class="h4"><a href="'.get_the_permalink().'">' . get_the_title() . '</a></h2>'; }Hi,
Thank you for your quick reply. It seems to be a good way to do it, but I don’t know how I can exclude sections IDs. I am very bad at coding, please let me know how to do it.
Thanks
If the elements are rendered with a CSS ID you can use CSS to define the format of the titles etc.
Something like:#2345 {
font-size: 12px;
font-weight: normal;
}where
#2345is the section ID.I hope that helps you to figure it out.
Feel free to get back to us if you have further questions.Hi @zelph14,
We’ve not heard back from you in a while, so I’m marking this thread as resolved. Hopefully, you were able to find a solution to your problem!
If you have further questions, please feel free to open a new topic.
Thanks.
The topic ‘Not apply functions.php changes to a specific element’ is closed to new replies.