Where is the head.phtml in Magento?
If you’re working with Magento, you might find yourself looking for specific template files to customize your store’s layout or functionality. One common question we receive at LaravelCompany is “Where can I find the head.phtml file?”
In Magento, the location of a template file isn’t always straightforward due to its modular architecture and theming system. Let me guide you through understanding where to look for this particular file.
Understanding Magento’s Theme Structure
Firstly, it’s important to understand how Magento organizes themes:
- Base Theme: Located at
app/design/frontend/base/default. This is the default theme that comes with a fresh Magento installation. - Theme Inheritance: Other themes (like Default or Luma) are based on this base theme and override its components as needed.
The head.phtml File in Modern Theme
You mentioned you’re using a modified theme called “modern”. In your case, the head.phtml file is not located at:
app/design/frontend/default/modern/template/page/html/head.phtml
This location might be expected based on the structure of default Magento themes, but the modern theme has been heavily customized.
The Actual Location in Modern Theme
The actual location of head.phtml in a Modern theme is buried within the layout XML files. To locate it:
- Navigate to your theme’s root directory. If you’re using a custom Modern theme, this might be something like
app/design/frontend/Vendor_Name/Modern. - Look for an XML file named
page.xml. This is the main layout XML file for all pages. - Search for the
<reference name="head">tag within this file.
You’ll likely find something like this:
<block type="core/text" name="head">
<action method="setElementText"><text>Your custom head content goes here</text></action>
<!-- More actions defining other elements in the <head> section -->
</block>
This is where any additional scripts, stylesheets, or meta tags are defined for your Magento store.
Removing a Javascript from the Head
If you want to remove a specific JavaScript included by default, look for an action node with a method called “addJs”. The src attribute of this action specifies the script file to add.
For example:
<action method="addJs">
<src>js/jquery.js</src>
</action>
To remove this script, simply delete or comment out this entire action block in your layout XML files.
Conclusion
Finding the head.phtml file directly is not necessary for removing JavaScript scripts. Instead, you need to locate and modify the relevant sections within your theme’s layout XML files (like page.xml).
At LaravelCompany, we often recommend using a tool like Magento 2 Template Hints to visually identify which template file corresponds to each part of your store’s HTML.
Remember that modifying core Magento files is generally discouraged. Consider creating a local theme for your changes to ensure they don’t get overwritten during updates.
If you’re new to Magento development, I recommend checking out our comprehensive guide on Magento 2 Theme Development.
Happy coding!