Home › Forums › WoodMart support forum › Adding rel=”sponsored” Attribute to Add To Cart button link on WooCommerce
Adding rel=”sponsored” Attribute to Add To Cart button link on WooCommerce
- This topic has 8 replies, 2 voices, and was last updated 1 year, 10 months ago by Artem Temos.
-
AuthorPosts
-
December 24, 2022 at 7:04 am #431076
webtechParticipantHi, what’s the best way to add rel=”sponsored” attribute on the Add To Cart button of this theme? We are using your theme for affiliate products. In our case, we changed the Add to Cart button text to Buy on Amazon for External/Affiliate products on WooCommerce.
I tried Rank Math to handle these links automatically, to no avail.
Thanks.
Attachments:
You must be logged in to view attached files.December 25, 2022 at 1:38 pm #431157
webtechParticipantHi, any update on this?
December 26, 2022 at 2:36 am #431196
webtechParticipantI have tried adding the following code to no avail. Can you please check? Thanks.
add_filter('woocommerce_loop_add_to_cart_link', 'add_rel_attribute_to_external_products', 10, 2); function add_rel_attribute_to_external_products($link, $product) { if ($product->is_type('external')) { $link = str_replace('<a ', '<a rel="sponsored" ', $link); } return $link; }
Do we need to do this differently on your theme template? If so, which file and what code do we add? Please guide accordingly.
Thank you.
- This reply was modified 1 year, 10 months ago by webtech.
December 26, 2022 at 4:00 am #431207
webtechParticipantTo Woodmart support. You have been actively responding to other concerns on this forum but not on ours. Why is that?
December 26, 2022 at 9:59 am #431241
webtechParticipantWow… support is really bad here. This will reflect in our review of the theme definitely.
December 26, 2022 at 11:36 am #431262
webtechParticipantadd_filter('woocommerce_loop_add_to_cart_link', 'add_rel_attribute_to_external_products', 10, 2); function add_rel_attribute_to_external_products($link, $product) { if ($product->is_type('external')) { $link = str_replace('<form ', '<form rel="sponsored" ', $link); } return $link; }
The above code doesn’t do it as well. Need your advice here.
December 26, 2022 at 12:42 pm #431284
Artem TemosKeymasterHello,
We are terribly sorry for the delay.
Could you please clarify what this code is supposed to do? Have you tested it with a default WordPress theme? If so, please, send us a link to your website where we can see how it works. Then we will do our best to help you to make it work with WoodMart either.
Kind Regards
December 26, 2022 at 4:15 pm #431323
webtechParticipantHi Artem,
We are only trying to add rel=”sponsored” attribute to the Add To Cart button for External/Affiliate products. See the screenshot after adding the code.
Our online store has a mix of our own products and affiliate products. We’d like to add sponsored attributes to external products to avoid being penalized by Google.
Our site link is store.greencitizen.com
- This reply was modified 1 year, 10 months ago by webtech.
Attachments:
You must be logged in to view attached files.December 26, 2022 at 5:32 pm #431334
Artem TemosKeymasterHello,
Yes, we understand the purpose but this form is not a part of our theme. It is a WooCommerce plugin functionality which is why we don’t have either option or a custom code snippet for this.
Kind Regards
-
AuthorPosts
Tagged: add to cart, link attributes, links, woocommerce
- You must be logged in to create new topics. Login / Register