Hello.

This is my code from Drupal 8.0.0 with your module:

// ...
<link rel="canonical" href="/page/article-1" />
<link rel="shortlink" href="/node/1" />
<link rel="delete-form" href="/node/1/delete" />
<link rel="edit-form" href="/node/1/edit" />
<link rel="version-history" href="/node/1/revisions" />
<link rel="revision" href="/page/article-1" />
//..

But this is very bad SEO practies! Help me to unset this meta tags, please!

Comments

Vikky Shostak created an issue. See original summary.

damienmckenna’s picture

Version: 8.x-1.0-beta2 » 8.x-1.x-dev
Component: Code » Documentation
Category: Bug report » Support request
Priority: Critical » Normal

Those are provided by core, not Metatag. I'll see if I can work out a way of doing that.

koddr’s picture

DamienMcKenna, what hook do this? May be I can write alter function for that? For example, hook_page_attachments_alter()?

damienmckenna’s picture

Give it a try, and also try hook_preprocess_html() too.

flocondetoile’s picture

Related issue #2406533 edit-form, delete-form etc.
tags added on /node/{node} are invalid according to W3C Validator
about these metatags added by core

Until this issue land, you can remove these metatags for Node using hook_entity_view_alter() and for Taxonomy Term using hook_page_attachments_alter(). For term your module's implementation must be after the taxonomy implementation

Anonymous’s picture

Anonymous’s picture

Status: Active » Closed (duplicate)

Actually..

sachbearbeiter’s picture

<?php
function epsenkaas_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
  if ($entity->getEntityType()->id() == 'node') {
    if (!empty($build['#attached']['html_head_link'])) {
      foreach ($build['#attached']['html_head_link'] as $key => $config) {
        if ($config[0]['rel'] != 'canonical' && $config[0]['rel'] != 'shortlink') {
          unset($build['#attached']['html_head_link'][$key]);
        }
      }
    }
  }
}
?>

#2406533: edit-form, delete-form etc. <link> tags added on /node/{node} are invalid according to W3C Validator

sachbearbeiter’s picture

A lot of bots are filling my log, calling this links ...
The previous example is not working for me ... maybe wrongly placed in the theme file by me ...
Can someone help or has an alternative script?

Thanks and regards
SB

koddr’s picture

Working solution: module Unset HTML head link and small article with instructions (RU).

fomenkoandrey’s picture

Actually

Anonymous’s picture

Hello Vikky,

thank you very much for this module!

Your current version removed most of these
tags.
But not all.

<link rel="book-outline-form" href="/node/1/outline" />
<link rel="book-remove-form" href="/node/1/outline/remove" />

were still present.

So I changed in unset_html_head_link.module file the $unset_html_head_link array to:

$unset_html_head_link = [
	'delete-form',
	'edit-form',
	'version-history',
	'revision',
	'book-outline-form',
	'book-remove-form',
];
Jean Lavialle’s picture

This code work fine for me

/**
 * Implements hook_page_attachments_alter().
 * @param array $attachments
 */
function my_module_page_attachments_alter(array &$attachments) {
  if (!isset($attachments['#attached']['html_head_link'])) {
    return;
  }
  $unset_html_head_link = [
    'canonical',
    'shortlink',
    'delete-form',
    'edit-form',
    'version-history',
    'revision',
  ];
  foreach ($attachments['#attached']['html_head_link'] as $key => $value) {
    if (isset($value[0]['rel']) && in_array($value[0]['rel'], $unset_html_head_link)) {
      unset($attachments['#attached']['html_head_link'][$key]);
    }
  }
}

/**
 * Implements hook_module_implements_alter().
 */
function my_module_module_implements_alter(&$implementations, $hook) {
  if ($hook === 'page_attachments_alter') {
    $group = $implementations['my_module'];
    unset($implementations['my_module']);
    $implementations['my_module'] = $group;
  }
}
kingjimza’s picture

Hi All,
My Content types pages (that are stock Drupal/bootstrap) and Taxonomy pages work fine and by that I mean the following is removed by this awesome Module;

<link rel="canonical" href="/about.htm" />
<link rel="shortlink" href="/node/2" />
<link rel="revision" href="/about.htm" />

My problems is that when I use Panels i.e."Panelize this view mode", the above meta's reappear.

Any ideas on what I would need to adjust or add on the "unset_html_head_link.module" file for this module to work happily with Panels?

Thanks
James

darkstartom’s picture

I've tried #14 and it works fine on a content page. However I need to use it on profile page created with the profile module, trying it here doesn't removed the links. Is there a way to do this for profiles? Thanks!

AndersNielsen’s picture

As said in #15, this does not seem to work for panel pages or panelized nodes. It seems like panels is adding the tags after the hook_page_attachments_alter() has been run somehow. But maybe this should go into a panels issue instead if it's something general for that module?

dpagini’s picture

FYI - just added this guy b/c I couldn't find anything else like this... https://www.drupal.org/project/panelizer/issues/2951038

Diane Bryan’s picture

@Jean Lavialle, I would love to implement your code, since my site isn't using panels or panelizer and I would like to be able to validate the site. But I don't know where the code goes. Any chance you can append some instructions for newbs? TAI!!!

gngn’s picture

@Diane Bryan :
you need to create a custom module - see Creating custom modules - and put the code in the .module file.

You need to replace my_module with the name of your module.
Enabled your module and that's it.