2

I want to add default head block in default.xml file. so if anyone have idea about it then please send me the solution.

3 Answers 3

2
  • For custom module use following.

    app/code/{{vendorname}}//{{modulename}}/view/frontend/layout/default.xml

and add css or js like as follows

<head>
    <link src="{{vendorname_modulename}}::js.js"/>
    <css src="{{vendorname_modulename}}::css/yourstyle.css"/>
</head>
  • Without module if you need in your theme do like this.

    Create following file under your theme

    app/design/frontend/VENDOR/THEME/Magento_Theme/layout/default.xml And add following code in your xml

2

Create app/design/frontend/VENDOR/THEME/Magento_Theme/layout/default_head_blocks.xml. Example:

<?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>
        <link rel="stylesheet" type="text/css" src="//cdn.jsdelivr.net/jquery.slick/1.5.9/slick.css" src_type="url" />
        <css src="css/styles-m.css" />
        <css src="css/styles-l.css" media="screen and (min-width: 641px)"/>
        <css src="css/print.css" media="print" />

        <script src="Magento_Theme::js/init.js"/>
    </head>
</page>
2

Create app/design/frontend/VENDOR/THEME/Magento_Theme/layout/default.xml.

Example:

<?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>
    <link src="{{vendorname_modulename}}::js/yourjs.js"/>
    <css src="{{vendorname_modulename}}::css/yourstyle.css"/>
</head>
</page>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.