Tos Web Developer provides insights, tutorials, and advice around topics including content strategy, design, Drupal Development, Drupal Custom Module Development, Drupal 8 Custom themes, PHP, Server, Twig, and more

 




Using if $nid is equal to added so add noindex in head tag for this we can using theme_preprocess_html() hook.

 function example_theme_theme_preprocess_html(&$variables)  
 {  
   // added tag in html for single page '<meta name="robots" content="noindex" />'  
   $node = \Drupal::routeMatch()->getParameter('node');  
   if ($node instanceof \Drupal\node\NodeInterface) {  
   // You can get nid and anything else you need from the node object.  
   $nid = $node->id();  
   }  
   if($nid == 136){  
     $noindex = [  
       '#tag' => 'meta',  
       '#attributes' => [  
         'name' => 'robots',  
         'content' => 'noindex',  
       ],  
     ];  
    $variables['page']['#attached']['html_head'][] = [$noindex, 'noindex'];  
   }  
 }  

Clear Drupal cache and check you given change on frontend.

Follow us on below social media for such amazing web development related and drupal related trick and tip.

Facebook :-  https://www.facebook.com/TOsTechhs/

Instagram :-  https://www.instagram.com/toswebdeveloper/

Twitter :-  https://twitter.com/TOs_Tech

Subsrcibe Youtube chaneel :-  https://www.youtube.com/channel/UCx4zugyGG2toEj9xd_0uAmg


No comments:

Post a Comment

| Designed And Blog Post by www.toswebdeveloper.com