Hi Experts,
Good Day!
I need to add some custom code inside the head tag to manipulate the tile and meta tags. in magento i it was easy to add in head.phtml but i am unable to find the same file in magento 2. please help me to accomplish this task.
Regards,
zia
You can directly add title and keywords in head tag from the backend of the magento admin panel !
Here is the link of detail steps from where you can go and add those title and keywords for the same - https://docs.magento.com/m2/ce/user_guide/design/html-head.html
this is for global let me know if you wanted to add still in head.phtml !
Hope it helps
Hi @Manthan Dave,
thanks for your reply.
Note: actually i want to do ON PAGE SEO.
I want to add some php scripts to handle the title and meta description dynamically. how can i do this?
Regards,
zia
ok i understand your problem here is the link for the same - https://stackoverflow.com/questions/48167553/magento-2-add-custom-script-just-after-head-tag
This will helps you to achieve add custom script just after head tag !
Same way if you wanted to do it via block(php) and phtml - you can do it by this way refer this link - https://magento.stackexchange.com/questions/147602/add-block-in-head-tag-in-magento-2/147606
Location of the file is : vendor/magento/moduletheme/view/frontend/templates/html/header.phtml
By default head.phtml file is not exist in magento 2,
There is header.phtml file is available for header related information.
header.phtml file location is,
vendor/magento/module-theme/view/frontend/templates/html/header.phtml
You can directly add your code from admin panel.
Go To Content -> Design -> Configuration,
Edit your theme,
Add code inside, Html Head Section,
Add your code in Script and Stylesheet field for Script and Style related code.
I already checked these links. here did not mention clearly which file has to create and where we can add php code. something like that.
Hi @Rakesh Jesadiya,
thanks for your reply.
Actually i need to handle on page seo. so i need to handle title and meta description dynamically with php code. i need to add this code into .phtml file. how can i do this! that is the issue right now.
vendor/magento/module-theme/view/frontend/templates/html/header.phtml
you need to override above file to your theme level and you can do it.
i found this file. but i did not see any coding regarding title, and description. or meta title.
Don't change in core files. Just follow below steps:
In head blocks write
<block class="Magento\Framework\View\Element\Template" name="head_file" template="Magento_Theme::html/<file name>.phtml">
Also you can add like below in default.xml
<referenceBlock name="head.additional">
<block class="Magento\Framework\View\Element\Template" name="frontuser" template="Magento_Theme::html/<filename>.phtml"/>
</referenceBlock>