DEV Community

surendra sahu
surendra sahu

Posted on

Google Search Console Meta Verification Issue in Angular and Its Solution

If you have built a website using Angular and when adding the Google Search Console meta verification tag, it automatically removes "/> and replaces it with ">, causing verification to fail, then this issue occurs due to Angular's template parsing mechanism.

๐Ÿšจ Reason for the Issue
Angular processes HTML differently and may modify self-closing tags () by converting them into a standard HTML format (). This happens because self-closing tags are not mandatory in HTML5, and Angular tries to optimize them.

๐Ÿ” Impact of the Issue
Google Search Console expects the exact meta tag format as provided, and if Angular modifies it, the verification process fails.

โœ… Solutions to Fix the Issue
1๏ธโƒฃ Use Angular's Meta Service to Add Meta Tags Dynamically
Instead of adding the meta tag directly in index.html, use Angular's Meta Service to ensure it remains unchanged:

import { Component } from '@angular/core';
import { Meta } from '@angular/platform-browser';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(private meta: Meta) {
this.meta.addTag({
name: 'google-site-verification',
content: 'YOUR_VERIFICATION_CODE'
});
}
}

This ensures that Angular does not modify the meta tag, and Google can read it correctly.

2๏ธโƒฃ Directly Edit index.html to Add the Meta Tag
If you are adding the meta tag in index.html, make sure it is inside the

section and that Angular does not override it:

๐Ÿ’ก Even if the self-closing /> is removed, it should not cause a problem. But if verification still fails, use the Meta Service method.

3๏ธโƒฃ Use Server-Side Rendering (SSR) with Angular Universal
If your website uses Server-Side Rendering (SSR), Angular might add meta tags after the page loads, which means Google may not detect them.
๐Ÿ”น Solution: Use Angular Universal (@angular/platform-server) so that meta tags are included in pre-rendered HTML before the page loads.

๐Ÿ”ฅ Conclusion
๐Ÿ‘‰ Angular modifies meta tags, which can cause Google Search Console verification to fail.
๐Ÿ‘‰ Using the Angular Meta Service API or modifying index.html directly can resolve this issue.
๐Ÿ‘‰ If your site uses SSR, then Angular Universal is the best solution.

๐Ÿ“Œ Still facing issues? Let me know in the comments! ๐Ÿš€

follow: egg rate today

Top comments (1)

Collapse
 
subhadra_official_47b673a profile image
Subhadra official • Edited

Is or the Correct Format for Google Search Console?
You are wondering whether the following formats are correct:
โŒ (Wrong?)
html

"google-site-verification"
content="Q9urmo8hKUQbgCE.......................................">
โœ… (Correct?)
html

"google-site-verification"
content="Q9urmo8hKUQbgCE......................................." />


Does the Difference Between and Matter?
๐Ÿ”น In HTML5, both formats are valid, but Angular's HTML parsing may automatically remove the self-closing slash (/>).
๐Ÿ”น Some strict parsers (like Google Search Console) may require the self-closing format (/>) to verify correctly.
๐Ÿ”น If Angular modifies it to , Google might not recognize it properly, leading to verification failure.


Solution - How to Fix This in Angular?
โœ… 1. Use Angularโ€™s Meta Service API
Use Angularโ€™s Meta Service API to dynamically inject the meta tag so that Angular does not modify it:
typescript

import { Meta } from '@angular/platform-browser';

constructor(private meta: Meta) {
this.meta.addTag({
name: 'google-site-verification',
content: 'Q9urmo8hKUQbgCE.......................................'
});
}
๐Ÿ”น This ensures that Angular does not alter the meta tag.


โœ… 2. Directly Add It in index.html (Ensure Angular Doesn't Modify It)
If you are adding it in index.html, make sure to place it inside

like this:
html

"google-site-verification"
content="Q9urmo8hKUQbgCE......................................." />
To prevent Angular from modifying it:
๐Ÿ”น Ensure angular.json does not modify "index.html".
๐Ÿ”น Use Server-Side Rendering (SSR) or prerendering if needed.


Conclusion
๐Ÿ‘‰ Google Search Console may require the self-closing format (/>).
๐Ÿ‘‰ Angular may modify it, causing verification to fail.
๐Ÿ‘‰ Use Angularโ€™s Meta Service API or properly place it in index.html.
๐Ÿ“Œ If verification still fails, check the generated HTML in Chrome DevTools (view-source:) to confirm the meta tag is correct. ๐Ÿš€