If we want to hide or unset or remove META Tag from our web page then we have to use `hook_page_attachments_alter` in `.theme` file.
we have to create an array and pass the name of `META name` which we want to remove or unset from web page.
like..
$unset_meta = [
'title', // Meta name "title"
'description', // Meta name "description"
'keywords', // Meta name "keywords"
'Generator' // Meta name "Generator"
];
then with the help of $page['#attached']['html_head'], page attachments html_head we have to check that meta name if exist then we have to unset this.
we are giving here an example for this..
Example:
function moldev_page_attachments_alter(array &$page) { // here moldev is my theme name.
// Define an array of META tags to remove.
$unset_meta = [
'title', // Meta name "title"
'description', // Meta name "description"
'keywords', // Meta name "keywords"
'Generator' // Meta name "Generator"
];
// Check values and delete.
foreach ($page['#attached']['html_head'] as $key => $value) {
if (in_array($value[1], $unset_meta)) unset($page['#attached']['html_head'][$key]);
}
}
if you want to delete/remove/unset any link rel="alternate" and hreflang="en" or any language then follow the below given code.
foreach ($page['#attached']['html_head_link'] as $key => $attachment) {
if ($attachment[0]['rel'] == 'alternate' && $attachment[0]['hreflang'] == 'en') {
unset($page['#attached']['html_head_link'][$key]);
}
}
Note: If have any suggestions or issue regarding 'How to remove or unset META tag from web page?' then you can ask by comments.
we have to create an array and pass the name of `META name` which we want to remove or unset from web page.
like..
$unset_meta = [
'title', // Meta name "title"
'description', // Meta name "description"
'keywords', // Meta name "keywords"
'Generator' // Meta name "Generator"
];
then with the help of $page['#attached']['html_head'], page attachments html_head we have to check that meta name if exist then we have to unset this.
we are giving here an example for this..
Example:
function moldev_page_attachments_alter(array &$page) { // here moldev is my theme name.
// Define an array of META tags to remove.
$unset_meta = [
'title', // Meta name "title"
'description', // Meta name "description"
'keywords', // Meta name "keywords"
'Generator' // Meta name "Generator"
];
// Check values and delete.
foreach ($page['#attached']['html_head'] as $key => $value) {
if (in_array($value[1], $unset_meta)) unset($page['#attached']['html_head'][$key]);
}
}
if you want to delete/remove/unset any link rel="alternate" and hreflang="en" or any language then follow the below given code.
foreach ($page['#attached']['html_head_link'] as $key => $attachment) {
if ($attachment[0]['rel'] == 'alternate' && $attachment[0]['hreflang'] == 'en') {
unset($page['#attached']['html_head_link'][$key]);
}
}
Note: If have any suggestions or issue regarding 'How to remove or unset META tag from web page?' then you can ask by comments.
No comments:
Post a Comment