Site Verification
Verifies ownership of a site for use with search engines by adding meta tags or serving verification files.
site_verify
Install
composer require 'drupal/site_verify:^3.0'
Overview
The Site Verification module simplifies the site/domain ownership authentication process for search engines and other external services. It provides a clean administrative interface to manage verification methods required by services like Google Search Console, Bing Webmaster Tools, and Yandex Webmaster.
The module supports two verification methods: meta tags that are automatically included on the site's front page, and text/HTML files served directly from the site root. This eliminates the need for manual file uploads via FTP or server access, as well as theme template modifications for meta tags.
Each verification is stored as a configuration entity, making it exportable and deployable across environments using Drupal's configuration management system. The module includes robust validation to prevent duplicate filenames and provides enable/disable functionality for temporary deactivation without deletion.
Features
- Meta tag verification: Automatically adds verification meta tags to the site's front page only, supporting services like Google, Bing, and Yandex
- File-based verification: Serves verification text or HTML files directly from the site root via dynamically generated routes
- Three input modes: Manual entry of verification details, paste a complete meta tag for automatic parsing, or upload a verification file
- Configuration entity storage: All verifications are stored as config entities, enabling export/import via Drupal's configuration management
- Enable/disable functionality: Temporarily deactivate verifications without deleting them, useful for testing or maintenance
- Automatic route rebuilding: Routes are automatically rebuilt when file-based verifications are added, modified, or removed
- Permission-based access control: Separate permissions for meta tag management and file-based verification management
- Validation constraints: Unique filename enforcement for file-based verifications and input sanitization
- Upgrade path: Automatic migration from legacy database storage (2.x branch) to config entity storage (3.x branch)
Use Cases
Google Search Console Verification
To verify your site with Google Search Console: 1) Log in to Google Search Console and add your property. 2) Select either 'HTML tag' or 'HTML file' verification method. 3) Copy the provided verification code. 4) In Drupal, go to Admin > Configuration > Search and metadata > Verifications > Add. 5) For meta tags, choose 'Paste a meta tag' and paste the full meta tag. For files, choose 'Upload a file' and upload the downloaded verification file. 6) Save and verify in Google Search Console.
Multi-environment Deployment
Since verifications are stored as configuration entities, they can be exported using drush config:export and deployed across environments. Create verifications on development, export config, and import on staging/production. File verifications work immediately after deployment as routes are rebuilt automatically.
Temporary Verification Deactivation
During site migrations or testing, you may need to temporarily disable verifications without losing the configuration. Use the Disable operation from the verification list to deactivate a verification. The configuration is preserved and can be re-enabled later with a single click.
Managing Multiple Search Engines
Create separate verifications for each search engine (Google, Bing, Yandex, etc.). Use descriptive labels like 'Google Search Console Production' and descriptions noting the account or purpose. All meta verifications are output together on the front page.
Third-party Service Verification
Many services beyond search engines use similar verification methods, including Pinterest, Facebook domain verification, and various SEO tools. Any service that verifies via meta tags or served files can use this module.
Tips
- Use descriptive labels and descriptions to easily identify which service each verification is for, especially when managing multiple search engines
- The 'Paste a meta tag' input mode is the fastest way to add verifications - simply copy the full meta tag from the search engine's interface
- File verifications can serve any content as plain text, making them useful for various verification services beyond search engines
- Export verifications using configuration management to easily deploy them across development, staging, and production environments
- Use the disable feature instead of delete when you need to temporarily remove a verification, such as during site migrations
- The default verification type can be preset via URL parameter: /admin/config/search/verifications/add?type=file or ?type=meta
Technical Details
Admin Pages 6
/admin/config/search/verifications
Lists all site verification entities with their status, type, and name. Provides operations to edit, enable/disable, or delete each verification. File-based verifications show clickable links to their served URLs.
/admin/config/search/verifications/add
Create a new site verification using one of three input methods: manual entry of type/name/content, parsing a pasted meta tag, or uploading a verification file.
/admin/config/search/verifications/{site_verification}/edit
Modify an existing site verification. The form is identical to the add form but pre-populated with existing values.
/admin/config/search/verifications/{site_verification}/delete
Confirmation page to permanently delete a site verification.
/admin/config/search/verifications/{site_verification}/enable
Confirmation dialog (modal) to enable a disabled site verification.
/admin/config/search/verifications/{site_verification}/disable
Confirmation dialog (modal) to disable an active site verification without deleting it.
Permissions 2
Hooks 2
hook_page_attachments
Adds meta tag verifications to the front page. Only executes on the front page path and attaches meta tags for all enabled Meta type verifications.
hook_help
Provides help text on the verification collection page and add form, explaining the two verification methods and how to use them.
Troubleshooting 6
File-based verifications require route rebuilding. Clear caches using drush cr or the Performance admin page. If the problem persists, check that the verification is enabled (Status = Yes) and the filename doesn't conflict with existing routes.
Meta tags only appear on the site's configured front page, not on /node or other paths. Verify that: 1) The verification is enabled, 2) The type is set to 'Meta', 3) You are viewing the actual front page URL. Clear caches after making changes.
The File type option is only available to users with the 'Manage file type site verifications' permission. Check that your role has this permission in the Permissions admin page.
The file upload functionality requires the core File module to be installed. Enable the File module, then return to the verification form.
Each file-based verification must have a unique filename. Check existing verifications for one using the same filename. If needed, delete or modify the existing verification first.
Run database updates using drush updb or the update.php script. The post-update hook will automatically migrate verifications from the database table to configuration entities. Check the log for any migration errors.
Security Notes 4
- The 'Manage file type site verifications' permission is restricted because file verifications can serve arbitrary content from the site root, which could potentially be exploited
- File verifications are served with Content-Type: text/plain to prevent potential XSS attacks
- Both permissions have 'restrict access: TRUE' meaning they should only be granted to trusted administrator roles
- Verification content is validated to prevent control characters and multi-line content in descriptions and filenames