We publish art (specific post type) on our website, and some of it may contain nudity.
We want to make sure that not the whole website will be blocked by safesearch on Google. So we only want to mark these specific art pages by using this guide: hidden link
Is this possible with toolset, and how should I do that?
While there's no specific bultin function I can think off within Toolset, it is easy to implement something like that with a little custom code.
First, for your CPT art, you can add a new boolean custom field, eg.: 'explicit_content'. Then for the posts you want to add the adult meta tags you mark that field to be true.
Then you can use a code similar to this to check if it is from the CPT art and if the field explicit_content is true to add the needed meta tags as indicated by Google:
function add_safesearch_meta_tag() {
if ( is_singular('art') ) { // 'art' is the CPT slug
$explicit_content = get_post_meta(get_the_ID(), 'explicit_content', true); // Replace 'explicit_content' with your field slug
if ( $explicit_content ) {
echo '<meta name="rating" content="adult">';
}
}
}
add_action('wp_head', 'add_safesearch_meta_tag');
You can add it to your theme's functions.php file or to the Toolset Settings > Code Snippets.
The code is meant to nudge you in the right direction, you might need to adapt it to your own scenario and review the needed meta tags for Google to properly classify those items.
Thank a lot! Unfortunately i'm absolutely not good with coding. But I made an 18 + checkbox within the post field group and that works . the field slug is: 18-plus and the singular slug for art is: Kunstwerk
So if i add this code, would that be sufficient?:
function add_safesearch_meta_tag() {
if ( is_singular('Kunstwerk') ) { // 'art' is the CPT slug
$explicit_content = get_post_meta(get_the_ID(), '18-plus', true); // Replace 'explicit_content' with your field slug
if ( $explicit_content ) {
echo '<meta name="rating" content="adult">';
}
}
}
add_action('wp_head', 'add_safesearch_meta_tag');
Can you please try to use the following code and try to resolve your issue:
function add_safesearch_meta_tag() {
if ( is_singular('kunstwerk') ) { // 'art' is the CPT slug
$explicit_content = get_post_meta(get_the_ID(), 'wpcf-18-plus', true); // Replace 'explicit_content' with your field slug
if ( $explicit_content ) {
echo '<meta name="rating" content="adult">';
}
}
}
add_action('wp_head', 'add_safesearch_meta_tag');