admin管理员组文章数量:1316974
I'm working on a Woocommerce website were I have multiple product types: simple_product, enviso_group_offer and enviso_group_ticket. All of these types are just products in my Woocommerce.
No I want to add the noindex, nofollow meta tag to only the enviso_group_ticket products.
<meta name=”robots” content=”noindex,nofollow”/>
How can I achieve that? When I'm using the SEO plugin Yoast, I can only target all the Products, instead of a specific product type.
At this moment, I've done it with the following code, but I feels not the right way to do so:
$product_type = get_the_terms( $product_id,'product_type')[0]->slug;
if($product_type == "enviso_group_ticket") {
?>
<script>
jQuery(function ($) {
$('head').append('<meta name=”robots” content=”noindex,nofollow”/>');
})
</script>
<?php
}
Can this be done with a Wordpress hook? Or should it be done differently? I know that I can achieve it by adding the noindex and nofollow on every enviso_group_ticket manually, but I want to force it automatically.
Thanks.
I'm working on a Woocommerce website were I have multiple product types: simple_product, enviso_group_offer and enviso_group_ticket. All of these types are just products in my Woocommerce.
No I want to add the noindex, nofollow meta tag to only the enviso_group_ticket products.
<meta name=”robots” content=”noindex,nofollow”/>
How can I achieve that? When I'm using the SEO plugin Yoast, I can only target all the Products, instead of a specific product type.
At this moment, I've done it with the following code, but I feels not the right way to do so:
$product_type = get_the_terms( $product_id,'product_type')[0]->slug;
if($product_type == "enviso_group_ticket") {
?>
<script>
jQuery(function ($) {
$('head').append('<meta name=”robots” content=”noindex,nofollow”/>');
})
</script>
<?php
}
Can this be done with a Wordpress hook? Or should it be done differently? I know that I can achieve it by adding the noindex and nofollow on every enviso_group_ticket manually, but I want to force it automatically.
Thanks.
Share Improve this question edited Nov 7, 2020 at 17:25 Dennis asked Nov 7, 2020 at 17:11 DennisDennis 1358 bronze badges1 Answer
Reset to default 1You can try the wp_head
hook:
add_action( 'wp_head', 'check_for_enviso_group_ticket' );
function check_for_enviso_group_ticket() {
if ( is_product() && ( 'enviso_group_ticket' == get_the_terms( get_the_ID(), 'product_type' )[0]->slug ) ) {
echo '<meta name="robots" content="noindex,nofollow"/>', PHP_EOL;
}
}
or to not break your site in case the WooCommerce is disabled and the is_product()
function isn't defined:
add_action( 'wp_head', 'check_for_enviso_group_ticket' );
function check_for_enviso_group_ticket() {
if ( is_singular( array( 'product' ) ) && ( 'enviso_group_ticket' == get_the_terms( get_the_ID(), 'product_type' )[0]->slug ) ) {
echo '<meta name="robots" content="noindex,nofollow"/>', PHP_EOL;
}
}
本文标签: woocommerce offtopicForce meta data on specific product type
版权声明:本文标题:woocommerce offtopic - Force meta data on specific product type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742009664a2412649.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论