• Resolved rjnagle

    (@rjnagle)


    I am working on a small website that is self-hosted on my own server. However, I need to add certain customizations to the HEAD section. That includes Google tracking code but also a special code to tag something as adult content (i.e., not for kids). (see https://developers.google.com/search/docs/crawling-indexing/safesearch ) It basically looks like this:

    <meta name="rating" content="adult">

    An alternate way to tag is to include this flag:

    <meta name="rating" content="RTA-5042-1996-1400-1577-RTA">

    Where do you go to add this meta tag? I’m on a new WP site using the 2023 theme and Full site editor. I’m probably a power user on WP, though certainly no developer. Some of the docs mention editing the header.php (this might be outdated information), but I see that the header.php file is deprecated, and I can’t figure where else to go. I have access to the php files if necessary.

    I also see that SEO plugins like Yoast or AIOSEO offer a way to edit meta information, but I can find no information to include a tag like this via either plugin. I was probably going to install a free version of one SEO plugin.

    This seems like an easy — almost trivial task, and yet I can’t find good up-to-date info. I’d prefer not to download a single-purpose plugin. I’m not looking for a mature content popup, just a way to tag the site’s content globally so search engines and content filters know what to do with this content on this site. Thanks.

    • This topic was modified 3 years, 1 month ago by rjnagle.
    • This topic was modified 3 years, 1 month ago by rjnagle.
Viewing 4 replies - 1 through 4 (of 4 total)
  • In your themes functions.php file, or in a new plugin that you create for this, you can add in this code:

    function set_adult_rating() {
        echo '<meta name="rating" content="adult">';
    }
    
    add_action( 'wp_head', 'set_adult_rating' );
    Thread Starter rjnagle

    (@rjnagle)

    Wow, that actually worked. Thanks!

    By the way, my 2023 theme directory doesn’t have a functions.php file, so I appended it to wp-includes/footer.php file. Is it possible that this file will be overwritten in a future WP update?

    Is it possible that this file will be overwritten in a future WP update?

    100% yes.

    The best option might be to create a small plugin file for that, and just use that instead. It will do the same job, just needs a tiny bit more coding.

    <?php
    /**
     *  Plugin Name: Add adult meta tag
     */
    
    function set_adult_rating() {
        echo '<meta name="rating" content="adult">';
    }
    
    add_action( 'wp_head', 'set_adult_rating' );

    Save that as a new file, and upload that to your plugins folder. Then activate it and it will do the same thing, with no worry about it being over-written.

    Oh, and don’t forget to remove the code from your footer file. 🙂

    Thread Starter rjnagle

    (@rjnagle)

    Thanks, while you were typing your comment, I was reading around and about to reach the same conclusion. A site-specific plugin seems like the perfect way to do this… Once again, this helped a lot!

    Update: I created a folder with the plugin name in wp-content/plugins and then called the file adult-rating.php . I wasn’t sure if the php code needed an end tag, but after some checking, I see that it didn’t need it at all. It was detected on the plugin page and activated successfully.

    • This reply was modified 3 years, 1 month ago by rjnagle.
    • This reply was modified 3 years, 1 month ago by rjnagle.
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Adding meta name=”rating” tags — how?’ is closed to new replies.