The code below hide from google a product that have a value “b2b” on a custom field.
Note #1: I used a ACF function to call the custom field, but you can use get_post_meta
Note#2: Required Yoast seo
1 2 3 4 5 6 7 8 9 10 11 | // run the action add_filter( 'wpseo_robots' , 'yoast_noidex' , 999); function yoast_noindex( $string ) { if (is_product()){ $limitazioni = get_field( "product_visibility" ); //ACF if ( $limitazioni == 'b2b' ){ $string = "noindex, nofollow" ; } } return $string ; } |
Will return <meta name=”robots” content=”noindex, nofollow” /> if true.
If false <meta name=”robots” content=”index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1″ />
This code will have priority on the yoast configuration in the product page
Questions? Suggestions? Please leave a comment below.