Shopify Custom Fonts: The Mobile Mystery Solved for Agencies
Hey EShopSet community! We've all been there – you've nailed the branding for a client, picked the perfect custom font, implemented it, and it looks absolutely stunning on desktop. Then, you pull it up on your phone, and… crickets. The beautiful font is gone, replaced by a generic fallback, making the site look, well, less than professional. It's a frustrating hiccup that can throw a wrench into even the most streamlined agency workflow automation.
This exact scenario recently popped up in a community discussion, and the original poster's journey to a solution offers some fantastic insights for any agency owner, PM, or ecommerce developer dealing with Shopify. Let's dive into what went wrong and, more importantly, how to get it right.
The Custom Font Conundrum on Shopify Mobile
The problem started with a developer using Shopify's Dawn 15.1.0 theme, trying to implement a custom brand font. They had uploaded the necessary webfont files (woff2, woff, ttf, and even otf) to Shopify's Files section. Their approach involved adding two @font-face blocks to their assets/base.css file, followed by a universal application:
@font-face {
font-family: "NAME";
font-display: swap;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: antialiased;
src: url("NAME.woff2" | asset_url) format("woff2"),
url("NAME.woff" | asset_url) format("woff"),
url("NAME.ttf" | asset_url) format("truetype");
}
@font-face
font-family: "NAME";
font-display: swap;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: antialiased;
src: url("URL FOR WOFF2" | file_url) format("woff2"),
url("URL FOR WOFF" | file_url) format("woff"),
url("URL FOR TRUETYPE" | file_url) format("truetype"),
url("URL FOR OTF" | file_url) format("otf");
And then, to apply it everywhere:
body * {
font-family: "NAME" !important;
}
While this worked perfectly on desktop, mobile devices stubbornly refused to display the custom font. The developer had already checked common culprits: inspecting elements (desktop showed correct loading), verifying font formats (woff2 was present), and confirming hosting (files were in Shopify's Files section). So, what was the missing piece?
The Breakthrough: Redundancy and URL Peculiarities
After some dedicated troubleshooting, the original poster cracked the code. The solution, as often happens in development, came down to a few subtle but critical adjustments:
- Redundant
@font-faceBlocks: There were two@font-facedeclarations for the same font. The first one, using| asset_url, was unnecessary and, in this case, problematic. Shopify'sasset_urlfilter is typically for files within the theme'sassetsdirectory. When you upload fonts via the Shopify admin's 'Files' section, you get direct, absolute URLs. - Incorrect
| file_urlFilter Usage: The second@font-faceblock correctly used absolute URLs (which you get from the Shopify Files section), but it still included the| file_urlfilter. When you're using the direct URL provided by Shopify's Files, this filter isn't needed and can actually interfere with the path resolution on some browsers, especially mobile ones. The direct URL is already absolute and ready to use. - Streamlining Font Formats: The
otffile was removed from the declarations, deemed unnecessary. While not directly causing the mobile issue, simplifying your font stack to essential modern formats (woff2, woff, ttf) is generally good practice for performance and compatibility.
Once these changes were made – specifically, removing the redundant block and stripping the | file_url filter from the direct URLs – the custom font magically appeared correctly on mobile devices!
How to Correctly Implement Custom Fonts on Shopify for Agencies
Drawing from this experience, here’s a robust approach for your agency to ensure custom fonts display flawlessly across all devices:
- Upload Font Files to Shopify Files: Go to your Shopify admin > Settings > Files. Upload your font files (at minimum,
.woff2and.wofffor broad support;.ttfcan be a good fallback). Make sure to copy the direct URL for each file. - Create a Single
@font-faceDeclaration: In your theme's CSS (e.g.,assets/base.cssor a dedicated custom CSS file), add a single@font-facerule. Use the absolute URLs you copied directly, without any Shopify Liquid filters like| asset_urlor| file_url. - Example Correct Code:
@font-face { font-family: "YourCustomFontName"; font-display: swap; /* Important for performance and user experience */ src: url("https://cdn.shopify.com/s/files/1/xxxx/files/yourfont.woff2") format("woff2"), url("https://cdn.shopify.com/s/files/1/xxxx/files/yourfont.woff") format("woff"), url("https://cdn.shopify.com/s/files/1/xxxx/files/yourfont.ttf") format("truetype"); } - Apply the Font via CSS: Once declared, your custom font is available. You can apply it universally or to specific elements using standard CSS. For universal application:
body { font-family: "YourCustomFontName", sans-serif; /* Add a fallback generic font */ } /* Or for specific elements */ h1, h2 { font-family: "YourCustomFontName", serif; }If you don't want to set the font universally, you simply target the specific elements (e.g.,
h1,.product-title,p.hero-text) with your CSS. There's no need to re-upload files or redo anything when code updates occur, as long as your@font-facedeclaration remains valid. - Test Thoroughly: Always test on multiple devices and browsers (especially iOS and Android devices) to catch any rendering quirks. This is a crucial step in any effective agency workflow automation.
EShopSet Team Comment
This community discussion brilliantly highlights a common, yet often perplexing, issue in Shopify development. The original poster's methodical troubleshooting and clear documentation of their solution are invaluable. We at EShopSet see this as a prime example of how small syntax errors or misunderstandings of Shopify's asset pipeline can lead to significant design inconsistencies. For agencies, this underscores the critical need for standardized CSS implementation practices and rigorous cross-device testing within your development workflows to prevent such issues from impacting client delivery.
Getting custom fonts right across all devices is a cornerstone of maintaining brand consistency and delivering a polished client experience. By understanding these nuances of Shopify's asset handling and implementing a clean, correct @font-face declaration, you can save your agency a lot of headache and ensure your clients' sites look sharp everywhere. Happy coding!
