There are two ways to add custom script to head tag in Magento 2:
- add custom script through admin-panel
- add custom script through XML
- If you want to add custom script in head tag through admin-panel, just login to the admin and browse the navigation Content => Design => Configuration, Now click on edit link of current theme and Go to HTML Head tab and inside scripts and style sheets text-area you can enter your custom script.
- If you want to add custom script through XML, just create a XML file on following location:
app/design/frontend/packagename/themename/Magento_Theme/layout/default_head_blocks.xml
and add the following code in this XML to call template file:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="head.additional">
<block class="Magento\Framework\View\Element\Template" name="header_tags" template="Magento_Theme::html/header/head_tags.phtml"/>
</referenceBlock>
</body>
</page>
Now create a template file on following location:
app/design/frontend/packagename/themename/Magento_Theme/templates/html/header/head_tags.phtml
and add script in this file, which you want to display in head tag.
Comments
Post a Comment