Skip Navigation

[Resolved] Tell Google about adult pages

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 3 voices.

Last updated by Minesh 3 months ago.

Assisted by: Minesh.

Author
Posts
#2749426

Hi,

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?

#2749545

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

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 you,
Mateus

#2750690
Schermafbeelding 2024-09-21 191236.png
Schermafbeelding 2024-09-21 190556.png

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');

#2754106

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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');
#2758049

Yes that works!

This line is added to the source code of the 18+ pages:

</noscript><meta name="rating" content="adult"><style id='wp-fonts-local'>

Is that what you expected the code to do?

#2758058

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes as suggested with the Doc:
- hidden link

It should add the following line of the code:
<codde>
<meta name="rating" content="adult">
[/php]

#2758069

You're the best! Thanks a lot