I am trying to include custom css and js in custom theme and should come on all pages.
I have tried this from the Magento DevDocs, but I can't make it right and it's not showing. Please help me.
2 Answers 2
For keep css and js in all pages you have to customize default_head_blocks.xml file. set file,
magento2/app/design/frontend/{Vendor}/{themename}/Magento_Theme/layout/default_head_blocks.xml file
Put inside <head> tag,
<css src="css/styles.css"/>
<script src="js/custom.js"/>
Add your css file inside,
app/design/frontend/{Vendor}/{theme}/web/css/styles.css
Add your custom js
app/design/frontend/{Vendor}/{theme}/web/js/custom.js
Remove cache folder and try.
Its now working in all pages of site.
-
Thanks. Although i have tried this and i was not aware that it will convert into .min.css. Actually it was there morning also. I was looking for my css. :)Shyam Krishna Sreekumar– Shyam Krishna Sreekumar2016年02月17日 11:05:34 +00:00Commented Feb 17, 2016 at 11:05
-
also if we are editing the css, always its rendering from pub static folder and every time we need to refresh to see the css change in frontend. Is there any possible way to see css change every refresh of page?Shyam Krishna Sreekumar– Shyam Krishna Sreekumar2016年02月17日 11:07:22 +00:00Commented Feb 17, 2016 at 11:07
-
apply command php bin/magento deploy:mode:set developer && php bin/magento cache:cleanRakesh Jesadiya– Rakesh Jesadiya2016年02月17日 11:11:05 +00:00Commented Feb 17, 2016 at 11:11
-
after done above command , deploy theme using, php magento setup:static-content:deploy, may be solve your issue.Rakesh Jesadiya– Rakesh Jesadiya2016年02月17日 11:11:40 +00:00Commented Feb 17, 2016 at 11:11
-
I Found This Magento2Site\vendor\magento\theme-frontend-blank\Magento_Theme\layout\default_head_blocks.xmlmatinict– matinict2018年01月30日 10:14:37 +00:00Commented Jan 30, 2018 at 10:14
When I updated my theme, my css files got deleted from app/design/bluesky/frontend/theme-name/web/css/custom.css and also the path from the default_head_block_xml.
Explore related questions
See similar questions with these tags.
php bin/magento setup:static-content:deploydid you deploy content?