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