All rules

Sheath rule

best-practices-no-duplicate-in-head

Certain <head> elements should not be duplicated.
Package
Core
Default severity
warning by default
Auto-fix
Manual fix

#Why

Some head elements should only appear once per document:

  • Multiple <title> tags confuse search engines and browsers
  • Multiple charset declarations can cause encoding issues
  • Duplicate meta tags for viewport, description, etc. override each other

#Examples

#Bad

<head>
<!-- Duplicate titles -->
<title>My Page</title>
<title>Another Title</title>
<!-- Duplicate charset -->
<meta charset="utf-8">
<meta charset="iso-8859-1">
<!-- Duplicate viewport -->
<meta name="viewport" content="width=device-width">
<meta name="viewport" content="initial-scale=1">
<!-- Duplicate description -->
<meta name="description" content="First description">
<meta name="description" content="Second description">
</head>

#Good

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Page description">
<title>My Page</title>
</head>

#Elements Checked

The rule reports duplicate instances of these document metadata elements.

Element Why Unique
<title> One title per document
<meta charset> One encoding declaration
<meta http-equiv="Content-Type"> Legacy charset
<meta name="viewport"> One viewport setting
<meta name="description"> SEO description
<meta name="author"> Document author
<meta name="robots"> Search engine directives
<meta name="theme-color"> Browser theme color

#Options

Use this option to define which named meta elements must be unique.

Option Type Default Description
uniqueMetaNames array ['viewport', 'description', 'author', 'robots', 'theme-color'] Meta name values that may occur only once

The configured list replaces the default and is matched case-insensitively:

<?php
'best-practices-no-duplicate-in-head' => ['warning', [
'uniqueMetaNames' => ['viewport', 'description', 'application-name'],
]],

Title and charset uniqueness are structural checks and are not controlled by this option.

#Notes

  • Only documents with a <head> element are checked
  • Open Graph and Twitter meta tags can have multiple values and are not checked
  • The first occurrence is valid; subsequent duplicates are flagged
  • A unique head element inside a potentially repeating Blade loop is flagged because it may render more than once; the @empty arm of @forelse is not repeating
  • A <title> or meta per arm of a conditional (@if ($seo) <title>...</title> @else <title>...</title> @endif) renders only one per page, so the rule does not report it; duplicates inside one arm, or against an unconditional element, still are reported

#References

#Related Rules