My requirement is to append magento 2 custom module JavaScript code inside the <head> tag for all the web pages.
-
do you want to add code in head tag ? on all pages ?Naveed Asim– Naveed Asim2018-09-25 10:17:38 +00:00Commented Sep 25, 2018 at 10:17
-
yes @NaveedAsimPankaj Sharma– Pankaj Sharma2018-09-25 10:18:03 +00:00Commented Sep 25, 2018 at 10:18
-
Do you want to add .js file in head?Sukumar Gorai– Sukumar Gorai2018-09-25 10:18:09 +00:00Commented Sep 25, 2018 at 10:18
-
No, @SukumarGorai my actual requirement is to append javascript code in head.Pankaj Sharma– Pankaj Sharma2018-09-25 10:19:20 +00:00Commented Sep 25, 2018 at 10:19
-
Can you update your js code which you want to add in head?Sukumar Gorai– Sukumar Gorai2018-09-25 10:20:17 +00:00Commented Sep 25, 2018 at 10:20
Add a comment
|
3 Answers
Create Vendor/moduleName/view/frontend/layout/default.xml
<?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">
<head>
<script src="js/test.js"/>
</head>
</page>
Follow the below steps:
in admin Go to
Content->Design
section and there you can add code in head section. like in here Design Head
