While building a new custom Shopify theme for a customer, I ran across the need for additional icons besides the 30 or so that come stock with Timber’s icon font. Here are the fonts that come with Timber out-of-the-box: https://shopify.github.io/Timber/#icons
This icon set is clearly lacking, but luckily Timber uses IcoMoon as their icon font of choice. While Timber doesn’t automatically include every icon in the IcoMoon library, we can rather easily add any IcoMoon icon we need. Here’s how:
- If you already have your theme downloaded locally, you can skip this step. Otherwise, you’ll need to download a copy of the
/assets/icons.json
file in your theme. This can be done several ways:- In your Shopify store admin dashboard, go to
Online Store > Themes > Actions > Edit Code
then browse toAssets/icons.json
. Copy and paste the entire contents of the file into a new file on your computer calledicons.json
. - In your Shopify store admin dashboard, go to
Online Store > Themes > Actions > Download Theme File
- By using the command line tool Theme Kit (https://shopify.github.io/themekit/)
- In your Shopify store admin dashboard, go to
- Browse to https://icomoon.io/app
- Import the
icons.json
file from your theme into IcoMoon. If you have downloaded the entire theme, this file is located in theAssets
directory. - If asked to import all the settings from your json file, say ‘Yes’.
- Now you are shown all the icons that are currently in the set. Scroll down, and select the icons you wish to add by clicking on them.
- Once you have selected the fonts you wish to add, click
Generate Font
in the lower right corner, and then click theDownload
button. A zip file containing some necessary files is downloaded to your computer. - Now we need to replace the icon files in your theme with the icon files that you downloaded. Open the downloaded zip file, extracting if necessary, then:
- Rename selection.json to icons.json
- Rename fonts/icomoon.ttf to icons.ttf
- Rename fonts/icomoon.eot to icons.eot
- Rename fonts/icomoon.woff to icons.woff
- Rename fonts/icomoon.svg to icons.svg
- Upload icons.json, icons.ttf, icons.eot, icons.woff, and icons.svg into the
Assets
directory of your theme, replacing the existing files. (It’s always a good idea to make a backup of the original files just in case something doesn’t work and you need to revert your changes) - Now you need to tell your theme’s CSS that these new icons exist. Go back to the zip file you downloaded from IcoMoon and open
style.css
in a text editor. - Scroll all the way to the bottom of the CSS file. You’ll notice that each of the new icons you added will have a CSS rule similar to this:
.icon-books:before { content: "\e920"; }
- Copy all the CSS rules for the icons you added. As of 12/5/17, the last icon in the original set is
.icon-rss
so you should just be able to copy everything below the.icon-rss
CSS rule. - Back in your theme files, open the main CSS stylesheet for the theme which is
Assets/timber.scss.liquid
. Find the Icon Mapping section (around line 1675). Paste your new icon’s CSS rules at the bottom of this section, after.icon-youtube:before { content: "\79"; }
There you have it. You can now access any IcoMoon icon from within your Timber Shopify theme. The CSS rule for your icon corresponds to the CSS class you just pasted into the main stylesheet. In my example, I can display the books icon using
<span class="icon icon-books"></span>
.