Magento – Magento 2 – Remove ‘Open Sans’ font

font familymagento2

How can I remove default fonts ('Open Sans', 'Helvetica Neue' and Helvetica)? I just use Arial and sans-serif only..

Thanks

Best Answer

To remove the fonts you can override the _typography.less file within your theme. I just did this as was using custom fonts and wanted to remove the unnecessary old fonts from being downloaded.

Move /vendor/magento/theme-frontend-blank/web/css/source/_typography.less to /app/design/frontend/Vendor/Theme/web/css/source/_typography.less and remove the font from the new _typography.less file.

& when (@media-common = true) {
.lib-font-face(
    @family-name: @font-family-name__base,
    @font-path: '@{baseDir}fonts/opensans/light/opensans-300',
    @font-weight: 300,
    @font-style: normal
);

.lib-font-face(
    @family-name: @font-family-name__base,
    @font-path: '@{baseDir}fonts/opensans/regular/opensans-400',
    @font-weight: 400,
    @font-style: normal
);

.lib-font-face(
    @family-name: @font-family-name__base,
    @font-path: '@{baseDir}fonts/opensans/semibold/opensans-600',
    @font-weight: 600,
    @font-style: normal
);

.lib-font-face(
    @family-name: @font-family-name__base,
    @font-path: '@{baseDir}fonts/opensans/bold/opensans-700',
    @font-weight: 700,
    @font-style: normal
);
}

Remove any of the above if they are not required anymore.

Update (Preload Tags)

Magento includes certain resources as preload tags when fonts are added via XML. The Magento core adds these fonts to XML within default_head_blocks.xml for the blank theme for the above fonts. Warnings shows in Chrome saying about fonts downloaded that aren't used if this is the case.

So additionally add below to your default_head_blocks.xml within your theme to make sure the files aren't still downloaded:

<head>
    ...
    <remove src="fonts/opensans/regular/opensans-400.woff2"/>
    <remove src="fonts/opensans/bold/opensans-700.woff2"/>
    ...
Related Topic