0

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.

  • file css or js just in custom theme/web/css/file-css-name.css then refresh cache. maybe help you. – xanka Feb 17 '16 at 9:06
  • php bin/magento setup:static-content:deploy did you deploy content? – Qaisar Satti Feb 17 '16 at 10:33
5

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 Feb 17 '16 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 Feb 17 '16 at 11:07
  • apply command php bin/magento deploy:mode:set developer && php bin/magento cache:clean – Rakesh Jesadiya Feb 17 '16 at 11:11
  • after done above command , deploy theme using, php magento setup:static-content:deploy, may be solve your issue. – Rakesh Jesadiya Feb 17 '16 at 11:11
  • I Found This Magento2Site\vendor\magento\theme-frontend-blank\Magento_Theme\layout\default_head_blocks.xml – matinict Jan 30 '18 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.