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>
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:...
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:
<!-- ...
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 ...
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 ...
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....
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:...
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(...
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 ...
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.
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 ...
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
...
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 ...
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="...
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 ...
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, ...
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:...
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">
&...
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:
...
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="...
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 ...
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 ...
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 ...
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"
...
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 ...
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::...
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
$...
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 ...
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-&...
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">
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
head × 73magento2 × 35
javascript × 17
layout × 15
magento-1.9 × 11
css × 9
blocks × 7
meta-tags × 5
html × 4
magento-1.7 × 3
theme × 3
xml × 3
header × 3
google-analytics × 3
link × 3
google-tag-manager × 3
event-observer × 2
adminhtml × 2
phtml × 2
cms × 2
script × 2
tags × 2
canonical × 2
meta × 2
default.xml × 2