Download the PHP package hryvinskyi/magento2-head-tag-manager without Composer
On this page you can find all versions of the php package hryvinskyi/magento2-head-tag-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hryvinskyi/magento2-head-tag-manager
More information about hryvinskyi/magento2-head-tag-manager
Files in hryvinskyi/magento2-head-tag-manager
Package magento2-head-tag-manager
Short Description HTML head tag manager for Magento 2 advanced element management capabilities
License MIT
Informations about the package magento2-head-tag-manager
Adobe Commerce / Magento 2 Head Tag Manager Module
This module provides a robust solution for managing HTML head elements in Adobe Commerce / Magento 2 applications. This module allows you to dynamically add, modify, and render various HTML head elements like meta tags, stylesheets, scripts, and other elements.
Features:
- CSP Compatible: Full support for Magento Content Security Policy
- Performance Optimized: Efficient element management and rendering
Key Features
- Add preconnect and prefetch links
- Add link elements (stylesheets, canonical, etc.)
- Add inline and external scripts with CSP support
- Add inline styles with CSP support
Installation
Composer Installation
Manual Installation
- Create directory
app/code/Hryvinskyi/HeadTagManager
- Download and extract module contents to this directory
- Enable the module:
Usage
Via ViewModel
Architecture
Cache Strategy
This module is not recommended for use on cached blocks, but this module provides a cache-aware architecture to handle head elements on cached blocks, and correctly render them.
Common Methods
addMetaName(string $name, string $content, ?string $key = null)
- Add meta tag with name attributeaddMetaProperty(string $property, string $content, ?string $key = null)
- Add meta tag with property attributeaddCharset(string $charset = 'UTF-8')
- Add charset meta tagaddStylesheet(string $href, array $attributes = [], ?string $key = null)
- Add stylesheet linkaddInlineStyle(string $content, array $attributes = [], ?string $key = null)
- Add inline styleaddExternalScript(string $src, array $attributes = [], ?string $key = null)
- Add external scriptaddInlineScript(string $content, array $attributes = [], ?string $key = null)
- Add inline script
Advanced Usage
Custom Elements
To add support for a new head element type:
- Create Element Class: Implement
HeadElementInterface
- Create Factory: Extend
AbstractHeadElementFactory
- Create Strategy: Implement
HeadElementSerializationStrategyInterface
- Register via DI: Add to
di.xml
configuration
Example Custom Element
Custom Factory
Custom Serialization Strategy
Custom Factory Registration
To register your custom element and factory, add the following to your di.xml
:
Usage
To use your custom element, simply call the factory from the HeadTagManager
:
Element Serialization
Custom serialization strategies allow for element-specific handling:
Integration
The module automatically injects head elements at the <!-- {{HRYVINSKYI:PLACEHOLDER:HEAD_ADDITIONAL}} -->
placeholder in your HTML output.
Version History
See CHANGELOG.md for detailed version history and migration notes.
Testing
The module includes comprehensive test coverage:
- Unit Tests: All core classes and interfaces
- Integration Tests: End-to-end functionality
- Cache Tests: Cache-aware functionality
Run tests with:
Contributing
Contributions are welcome! Please ensure:
- All tests pass
- New features include tests
- Code follows SOLID principles
- Documentation is updated
License
Copyright © 2025 Volodymyr Hryvinskyi. All rights reserved.