• Hello. How to Add Meta Noindex to Feeds, RSS and Trackback? maybe we could do with functions.php? how?

    thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Echo the meta tag out from inside a conditional that checks for is_feed() or is_trackback().

    This script could either be in header.php of a child theme, or in a function hooked into the action ‘wp_head’ from functions.php.

    Thread Starter devrekli

    (@devrekli)

    @bcworkz

    thanks you but Can you give me the code? ?? for fuctions

    Moderator bcworkz

    (@bcworkz)

    Something like this in the head section of your theme’s header.php template:
    <?php if(is_feed()||is_trackback()) echo '<meta name="robots" content="noindex">'; ?>

    Thread Starter devrekli

    (@devrekli)

    i added header.php but not working ??

    <head profile="https://gmpg.org/xfn/11">
    <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    <title><?php wp_title(' '); ?> <?php if(wp_title(' ', false)) { echo ' : '; } ?><?php bloginfo('name'); ?></title>
    <?php if(is_feed()||is_trackback()) echo '<meta name="robots" content="noindex">'; ?>

    maybe, feed pages can not use header.php? may need to be done with functions.php

    —————–
    also is true? for feed

    <meta name="robots" content="noindex">'; ?>

    or

    <xhtml:meta xmlns:xhtml="https://www.w3.org/1999/xhtml" name="robots" content="noindex" />

    THANKS

    Moderator bcworkz

    (@bcworkz)

    I’m sure you’re right on both counts, I don’t know much about feeds, as you probably surmised. I should have known the header template is not used though ?? So you do need to hook an action from functions.php. The ‘wp-head’ action won’t work, it’s for regular headers.

    A quick look at the feed templates indicates it depends on which template you use. For the default RSS2, the action should be ‘rss2_head’, so try adding this to your functions.php:

    add_action('rss2_head', 'feed_norobots');
    function feed_norobots() {
       echo '<xhtml:meta xmlns:xhtml="https://www.w3.org/1999/xhtml" name="robots" content="noindex" />';
    }

    Modify the action tag as needed if you use a different template, and double check the feed to ensure the tag ended up in the right place.

    The previous code should still work for trackbacks, IF I understand how they work, though of course you can remove the is_feed()|| part.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to Add Meta Noindex to Feeds, RSS and Trackback?’ is closed to new replies.