1

My requirement is to append magento 2 custom module JavaScript code inside the <head> tag for all the web pages.

5
  • do you want to add code in head tag ? on all pages ? Commented Sep 25, 2018 at 10:17
  • yes @NaveedAsim Commented Sep 25, 2018 at 10:18
  • Do you want to add .js file in head? Commented Sep 25, 2018 at 10:18
  • No, @SukumarGorai my actual requirement is to append javascript code in head. Commented Sep 25, 2018 at 10:19
  • Can you update your js code which you want to add in head? Commented Sep 25, 2018 at 10:20

3 Answers 3

2

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>
1

Follow the below steps:

  1. Goto Content -> Design -> Configuration
  2. Then edit the theme you are using for your store.
  3. Goto section HTML Head and add your script to Scripts and Style Sheets like below: enter image description here
0

in admin Go to

Content->Design

section and there you can add code in head section. like in here Design Head

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.