Skip to main content
8 votes

What is the proper way of positioning/ordering CSS files in Magento 2?

You can add the media attribute to the css element. This will add it to the end of all the included CSS in the head. <head> <css src="css/styles.css" media="all" /> </head>
andyace's user avatar
  • 89
8 votes
Accepted

Magento 2: How to add a meta tag based on layout

You can add as in HTML: your Layout would look like- <?xml version="1.0"?> <layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:...
Mohammad Mujassam's user avatar
8 votes

Add google tag manager code inside head and body

The basic GTM code can be added easily using the following three steps -: Step 1 gtm_head.phtml ---> YourTheme/Magento_Theme/templates/html/gtm_head.phtml add the following script: <!-- ...
Gagan Nayyar's user avatar
7 votes

What is the proper way of positioning/ordering CSS files in Magento 2?

I answered in detail here about how magento renders css and how the ordering is happening behind the scene. Some extra points I need to mention here is: If you want to render your custom css file ...
Rajeev K Tomy's user avatar
5 votes
Accepted

Magento 2: Add custom code before closing head tag

You can add your meta keywords or description in the product admin section under SEO Content tab. Or if you want to add your code file in the add then you can add your static block or file in the ...
Sumit's user avatar
  • 4,930
4 votes

Add inline javascript to head - magento2

I would advise using Require JS to load this rather than adding it via XML like this, but if you're adamant you want to do it this way try this: <!-- Bugherd --> <referenceBlock name="head....
Ben Crook's user avatar
  • 15.7k
4 votes

Adding <referenceBlock name=“head.additional”> Magento 2 not working

Create default.xml in app/code/Dfl/Marketplace/view/frontend/layout <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:...
Elsner Magento Development's user avatar
3 votes
Accepted

Can't get a head block in Observer

Your getBlock('head') returns false, so setData() cant work. Please try controller_action_layout_render_before_catalog_category_view event and an observer like ... public function setMetaTitle(...
sv3n's user avatar
  • 11.7k
3 votes

HTML Head issue using Magento2

Magento will store the content of Content > Design > Configuration > Theme Edit > HTML Head. within core_config_data using the path design/head/includes. You should be able to edit the ...
Douglas Radburn's user avatar
3 votes

Add tag "noscript" in HEAD for CSS files ( Magento 2)

You can add scripts from admin area. Navigate Admin -> Content -> Design -> Configuration -> [your theme] -> HTML Head. In this section you can add your scripts.
Greg's user avatar
  • 2,739
2 votes

Adding TypeKit code (or any code) into the Head of a Magento 2 site

To add using layout xml rather than database configuration use the following in app/design/frontend/<vendor_name>/<theme_name>/Magento_Theme/layout/default_head_blocks.xml <?xml ...
Andrew Kett's user avatar
  • 3,518
2 votes
Accepted

Understanding $this->getIncludes()

If you check in block file app/code/core/Mage/Page/Block/Html/Head.php you can see function getIncludes() /** * Get miscellanious scripts/styles to be included in head before head closing tag ...
Kul's user avatar
  • 1,807
2 votes

How to change the order of CSS files. Load module's CSS before theme's CSS in magento2?

There are two ways: 1> All css load depending on order in app/etc/config.php. You can move your module before Magento_theme module then it will load all css of your custom module before your theme ...
Yogesh Karodiya's user avatar
2 votes

Magento 2: How to add a meta tag based on layout

<reference name="head"> <block type="core/text" name="blockname"> <action method="setText"> <text> <![CDATA[<meta name="...
Visakh B Sujathan's user avatar
2 votes
Accepted

Add custom js to magento 2 after jquery

You should use Require JS to add the JS, loading it via the XML is not best practice. This is because Require JS can track dependencies and only load scripts when required, instead of unnecessarily ...
Ben Crook's user avatar
  • 15.7k
2 votes

Magento 2.1.5 Theme not loading correctly (worked perfect in 2.1.2)

Check what type id your theme has in the database, (theme table). apparently there is something called virtual themes that can cause issues like the one you describe. "Standard" themes have type 0, ...
c.norin's user avatar
  • 410
2 votes

Magento 2 : How to add custom meta tag in head

You can do it by update page_layout/2columns-left.xml <?xml version="1.0"?> <layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:...
Nikunj Vadariya's user avatar
2 votes

Set <head> title and script in Contact Page

you can try this : <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column"xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> &...
sami23's user avatar
  • 568
1 vote
Accepted

Magento2: Can we add current URL in "Scripts and Style Sheets"?

If you want set that value dynamically, you have to with PHP. You only can be use static url like {{media_url}} or {{base_url}}. You can create a new module for doing dynamically and do the next: ...
raumatbel's user avatar
  • 1,265
1 vote

Magento 2 : How to add custom meta tag in head

You can use head.additional and add a new block with a custom class and custom phtml <referenceBlock name="head.additional"> <block class="Vendor\Module\Block\CustomHead" name="...
Ahmed Atef's user avatar
1 vote

Add inline javascript to head - magento2

In Magento 2, referenceBlock (basically) is a replacement for reference, so using that should solve your first error. The second problem is that the name attribute for your block should be class ...
mtr.web's user avatar
  • 910
1 vote

Magento 1.9.2.4 How to remove Link Rel Stylesheet from head section on custom theme

Magento searches for a CSS/JS/image resource in the following manner: Current theme directory Default directory (if exists) of the current theme package Default directory under base theme package If ...
Mohit Kumar Arora's user avatar
1 vote

Magento 2: Include static resources (JavaScript, CSS, fonts) before </head>

you can add this code in an phtml file path: Magento_Theme/templates/html/header/head.phtml and call that file in default.xml as below <referenceBlock name="head.additional"> <block ...
Kajal's user avatar
  • 11
1 vote

Magento 2: Include static resources (JavaScript, CSS, fonts) before </head>

In your app/design/frontend/MODULE/NAME/Magento_Theme/layout/default.xml you can put a following code <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...
K. Maliszewski's user avatar
1 vote

Add inline javascript to head - magento2

You can easily add inline javascript in head from admin. To add javascript please follow below steps: Open your site admin Go to Content > Configuration Edit your current theme Click on HTML Head ...
Technocracker's user avatar
1 vote

Add inline javascript to head - magento2

Add this to your theme's default.xml: <referenceContainer name="head.additional"> <block class="Magento\Framework\View\Element\Template" name="custom_head" template="Magento_Theme::...
Lez's user avatar
  • 2,947
1 vote

Can't get a head block in Observer

If you want to change layout using observer you can change your event to controller_action_layout_generate_blocks_after Then you can get your head block in observer method from below code $...
Piyush's user avatar
  • 5,904
1 vote

Add google tag manager code inside head and body

I would also note that Magento 2 Enterprise Edition has some built in support for GTM: http://docs.magento.com/m2/ee/user_guide/marketing/google-tag-manager.html This is also a relevant ...
thaddeusmt's user avatar
  • 1,395
1 vote
Accepted

how can I append custom block to head in adminhtml controller action

Admin head block won't automatically render and display all its children. You need to go to head template app/design/adminhtml/default/default/template/page/head.phtml and add: <?php echo $this-&...
Konstantin Gerasimov's user avatar
1 vote

Magento : Edit Head Tag of Specific Page

Simple solution for that GOto your layout file and write below code. Below code is for category page and product view page <catalog_category_default> <reference name="head"> ...
Murtuza Zabuawala's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible