skip to Main Content

I’m using yoast plugin for seo for the blog wordpress in my site
by default plugin assigns below meta tag for 404 page

<meta name="robots" content="noindex,follow"/>

I want to update this meta tag to the below one

<meta name="robots" content="noindex,nofollow"/>

I have gone through yoast plugin documentation
But didn’t find any solution
Can this be done using yoast plugin itself or Is thee any other way?

2

Answers


  1. In header.php file for your WordPress theme you can use the below code which uses the conditional tag , is_404 to check if it is 404 page and prints out the meta tag which you wish for. So use the options from yoast plugin wherever you need and if you want to change it for specific pages then you can use the conditional tags.

    <?php if(is_404()): ?>
    <meta name="robots" content="noindex,nofollow"/>
    <?php endif; ?>
    

    The above solution assumes that Yoast Plugin is not adding any meta tags to header. But if Yoast adds it’s own meta tags then you can try the below solution

    Add the code to functions.php file

    add_filter('wpseo_robots', 'yoast_no_home_noindex', 999);
    function yoast_no_home_noindex($string= "") {
        if (is_404()) {
            $string= "noindex,nofollow";
        }
        return $string;
    }
    
    Login or Signup to reply.
  2. In frontend/class-frontend.php of the plugin directory, change the following

    if ( is_search() || is_404() ) {
                    $robots['index'] = 'noindex';
                }
    

    into

    if ( is_search() || is_404() ) {
                $robots['index'] = 'noindex';
                $robots['follow'] = 'nofollow';
            }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search