Magento 2 Developement

Magento 2: How to add Google Font

You might already check Include static resources (JavaScript, CSS, fonts) article by magento team. They state that to add google font you need to update /Magento_Theme/layout/default_head_blocks.xml with

<link src="http://fonts.googleapis.com/css?family=Montserrat" src_type="url" /> 

But as a result it is not working. Correct code is

<link src="https://fonts.googleapis.com/css?family=Montserrat" src_type="url" rel="stylesheet" type="text/css" />

It wont work without additional parameters.

Google fonts used in our tutorial for Slider Revolution: How to insert HTML slider in Magento 2

Another case is when you want to specify font subset like &subset=latin,cyrillic. The solution is Replacing ampersand in the path with

&amp;amp;amp;

The problem seems that the xml code is escaped three times. If it does not work for you, try adding or removing the amp; part as many times as needed until it works.
Check github thread for complete information on this issue – https://github.com/magento/magento2/issues/2228

One thought on “Magento 2: How to add Google Font

Leave a Reply

Your email address will not be published. Required fields are marked *