# ¿Usar iconos de Font-Awesome 4 en el tema pero mantener FA5?

**URL:** https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776
**Category:** Development
**Created:** [27 Mayo, 2019 09:30 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776 "2019-05-27T09:30:16Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Chaboi\_3000](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chaboi_3000/32/163015_2.png) [@Chaboi\_3000](https://meta.discourse.org/u/Chaboi_3000)
#### Post date: [27 Mayo, 2019 09:30 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/1 "2019-05-27T09:30:16Z")

</div>

I want to use a certain FA4 icon in my theme, but still keep the FA5 icons, and I don’t want to downgrade to an older version. Is it possible to use a certain FA4 icon in a theme while keeping the others FA5?

---

<div class="post-metadata">

### Author: ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)
#### Post date: [27 Mayo, 2019 13:36 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/2 "2019-05-27T13:36:15Z")

</div>

Not recommended, but you can use the CDN script to add again the [FA 4.7](https://fontawesome.com/v4.7.0/get-started/?utm_source=fontawesome4.7) icons on your site.

Copy the script you will find in your email and paste it in the `/head` tab of your theme  
`<script src="https://use.fontawesome.com/xxxxxxxxxx.js"></script>`

You need also to whitelist the source (`https://use.fontawesome.com/xxxxxxxxxx.js`) adding the URL in the site setting `content security policy script src` to make the script work.

Then you will be able to use the old set of icons on your site.

PS: Note that there is no guarantee that this workaround will continue to work in the future.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [27 Mayo, 2019 14:50 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/3 "2019-05-27T14:50:32Z")

</div>

If you just want one icon from FA4, extract the SVG of said icon and add it as a custom icon following

> [@Introducing Font Awesome 5 and SVG icons](https://meta.discourse.org/t/introducing-font-awesome-5-and-svg-icons/101643/1):
>
> **Adding custom icons**
> 
> If you would like to have more icons than what’s available in FontAwesome, you can add your own SVG icons in a plugin or a theme.

---

<div class="post-metadata">

### Author: ![Chaboi\_3000](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chaboi_3000/32/163015_2.png) [@Chaboi\_3000](https://meta.discourse.org/u/Chaboi_3000)
#### Post date: [27 Mayo, 2019 21:50 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/4 "2019-05-27T21:50:31Z")

</div>

Thanks, @Falco, and @dax, but how would I reference that uploaded SVG icon?  
Currently, I’m trying to do this:

```plaintext
api.replaceIcon('shield-alt', '$old-icon);

```

But it leaves a blank space instead of loading the SVG icon. Am I doing something wrong?

---

<div class="post-metadata">

### Author: ![Chaboi\_3000](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chaboi_3000/32/163015_2.png) [@Chaboi\_3000](https://meta.discourse.org/u/Chaboi_3000)
#### Post date: [28 Mayo, 2019 00:17 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/5 "2019-05-28T00:17:05Z")

</div>

I also tried

```plaintext
api.replaceIcon('shield-alt', 'old-icon.svg');

```

but it also failed.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [28 Mayo, 2019 00:19 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/6 "2019-05-28T00:19:24Z")

</div>

Can you share a the theme-component github repository where this is failing?

---

<div class="post-metadata">

### Author: ![Chaboi\_3000](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chaboi_3000/32/163015_2.png) [@Chaboi\_3000](https://meta.discourse.org/u/Chaboi_3000)
#### Post date: [28 Mayo, 2019 00:21 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/7 "2019-05-28T00:21:44Z")

</div>

@Falco, here it is:  
[https://github.com/Chaboi45/OldMod-Icon](https://github.com/Chaboi45/OldMod-Icon)

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [28 Mayo, 2019 02:18 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/9 "2019-05-28T02:18:51Z")

</div>

You need to follow the instructions Falco linked earlier more closely:

> [@Introducing Font Awesome 5 and SVG icons](https://meta.discourse.org/t/introducing-font-awesome-5-and-svg-icons/101643/1):
>
> If you would like to have more icons than what’s available in FontAwesome, you can add your own SVG icons in a plugin or a theme.
> 
> _In themes_ : add the SVG sprite in your theme’s `/assets` folder, and reference it in `about.json` using the variable name `icons-sprite` . For a sprite called `my-icons.svg` , your assets.json should include this:
> 
> ```plaintext
> "assets": {
> "icons-sprite": "/assets/my-icons.svg"
> }
> 
> ```
> 
> _In plugins_ : simply include an SVG sprite file in the `plugins/your-plugin-name/svg-icons` folder (see [this example SVG sprite](https://raw.githubusercontent.com/discourse/discourse/master/vendor/assets/svg-icons/discourse-additional.svg)). Restart your server (if in dev) or rebuild the site if in a Docker container and your custom icons should be automatically available .

In your repository, the svg file needs to be a sprite and the variable name in `about.json` shouldn’t be `old`, it should be `icons-sprite`. Then to replace the icon in JS, you need to use the id from the sprite in `api.replaceIcon`.

---

<div class="post-metadata">

### Author: ![Chaboi\_3000](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chaboi_3000/32/163015_2.png) [@Chaboi\_3000](https://meta.discourse.org/u/Chaboi_3000)
#### Post date: [28 Mayo, 2019 03:32 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/10 "2019-05-28T03:32:31Z")

</div>

Ah, sorry, can you restate what I did wrong now?

- I have an SVG file in the assets folder named old.svg
- I reference it in about.json like this: `"icons-sprite": "/assets/old.svg"`
- In `common/head_tag.html`, I have the following code:

```plaintext
<script type="text/discourse-plugin" version="0.8">
    api.replaceIcon('shield-alt', 'icons-sprite');
    
</script>

```

But something’s wrong with what I did. Sorry for the annoyance I caused you, but I kind of want to finish this quickly.

---

<div class="post-metadata">

### Author: ![cjk77](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cjk77/32/151779_2.png) [@cjk77](https://meta.discourse.org/u/cjk77)
#### Post date: [28 Mayo, 2019 09:49 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/11 "2019-05-28T09:49:03Z")

</div>

> [@Chaboi\_3000](#):
>
> I have an SVG file in the assets folder named old.svg

You can’t use a regular SVG file – it needs to be a sprite file.

---

<div class="post-metadata">

### Author: ![Chaboi\_3000](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chaboi_3000/32/163015_2.png) [@Chaboi\_3000](https://meta.discourse.org/u/Chaboi_3000)
#### Post date: [28 Mayo, 2019 10:22 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/12 "2019-05-28T10:22:23Z")

</div>

Ok, I created a png sprite file, but I do I use that in my theme for `api.replaceIcon('shield-alt', 'icons-sprite')` ?:

 ![icons-sprite](https://global.discourse-cdn.com/meta/original/3X/c/9/c92718fa3fbc4facd0e23216fe95af31b57138cd.png)  
or just  
 ![icons-sprite](https://global.discourse-cdn.com/meta/original/3X/5/b/5bbaee533a88c3c09106bf2b3e2432ee1b7f6f3f.png)  
For the second image, it’s name is icons-sprite.png, and I want to use that for api.replaceIcon. How would I use it?

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [28 Mayo, 2019 15:22 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/13 "2019-05-28T15:22:35Z")

</div>

Let’s say your sprite file contents is this:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
  <symbol id="super-icon1" viewBox="0 0 1792 1792">
    <path d="M896 960v448q0 26-19 45t-45 19-45-19l-144-144-332 332q-10 10-23 10t-23-10l-114-114q-10-10-10-23t10-23l332-332-144-144q-19-19-19-45t19-45 45-19h448q26 0 45 19t19 45zm755-672q0 13-10 23l-332 332 144 144q19 19 19 45t-19 45-45 19h-448q-26 0-45-19t-19-45v-448q0-26 19-45t45-19 45 19l144 144 332-332q10-10 23-10t23 10l114 114q10 10 10 23z"></path>
  </symbol>
  <symbol id="super-icon2" viewBox="0 0 1792 1792">
    <path d="M883 1056q0 13-10 23l-332 332 144 144q19 19 19 45t-19 45-45 19h-448q-26 0-45-19t-19-45v-448q0-26 19-45t45-19 45 19l144 144 332-332q10-10 23-10t23 10l114 114q10 10 10 23zm781-864v448q0 26-19 45t-45 19-45-19l-144-144-332 332q-10 10-23 10t-23-10l-114-114q-10-10-10-23t10-23l332-332-144-144q-19-19-19-45t19-45 45-19h448q26 0 45 19t19 45z"></path>
  </symbol>
</svg>

```

You need to have ids for each symbol, so that you can use those in JS, for example:

```js
api.replaceIcon('shield-alt', 'super-icon1')

```

---

<div class="post-metadata">

### Author: ![Chaboi\_3000](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chaboi_3000/32/163015_2.png) [@Chaboi\_3000](https://meta.discourse.org/u/Chaboi_3000)
#### Post date: [28 Mayo, 2019 22:42 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/14 "2019-05-28T22:42:58Z")

</div>

@pmusaraj, thanks, but how do I convert a single SVG icon into a sprite file?  
Current code:

```plaintext
<?xml version="1.0" encoding="utf-8"?>
<svg width="1792" id="oldm" height="1792" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1344 960v-640h-448v1137q119-63 213-137 235-184 235-360zm192-768v768q0 86-33.5 170.5t-83 150-118 127.5-126.5 103-121 77.5-89.5 49.5-42.5 20q-12 6-26 6t-26-6q-16-7-42.5-20t-89.5-49.5-121-77.5-126.5-103-118-127.5-83-150-33.5-170.5v-768q0-26 19-45t45-19h1152q26 0 45 19t19 45z"/></svg>

```

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [29 Mayo, 2019 01:47 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/15 "2019-05-29T01:47:28Z")

</div>

You could Google this and get a better answer, but you can try taking the `<path>` element and putting it inside of a symbol in the sprite.

---

<div class="post-metadata">

### Author: ![Chaboi\_3000](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chaboi_3000/32/163015_2.png) [@Chaboi\_3000](https://meta.discourse.org/u/Chaboi_3000)
#### Post date: [29 Mayo, 2019 04:24 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/16 "2019-05-29T04:24:30Z")

</div>

I converted mine to a sprite file, but GitHub says it’s invalid and all of the icons are broken now:

```plaintext
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id=”oldm” viewBox=”0 0 1792 1792”>
<path d=”M1344 960v-640h-448v1137q119-63 213-137 235-184 235-360zm192-768v768q0 86-33.5 170.5t-83 150-118 127.5-126.5 103-121 77.5-89.5 49.5-42.5 20q-12 6-26 6t-26-6q-16-7-42.5-20t-89.5-49.5-121-77.5-126.5-103-118-127.5-83-150-33.5-170.5v-768q0-26 19-45t45-19h1152q26 0 45 19t19 45z"></path>
</symbol>
</svg>

```

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [29 Mayo, 2019 15:46 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/17 "2019-05-29T15:46:52Z")

</div>

You might need to declare the XML encoding at the top of the file. Copy the contents of [https://raw.githubusercontent.com/discourse/discourse/master/vendor/assets/svg-icons/discourse-additional.svg](https://raw.githubusercontent.com/discourse/discourse/master/vendor/assets/svg-icons/discourse-additional.svg) from core, and replace the symbol tags in it with yours, and see if that works.

---

<div class="post-metadata">

### Author: ![Chaboi\_3000](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chaboi_3000/32/163015_2.png) [@Chaboi\_3000](https://meta.discourse.org/u/Chaboi_3000)
#### Post date: [18 Junio, 2019 08:00 UTC](https://meta.discourse.org/t/use-font-awesome-4-icons-in-theme-but-keep-fa5/118776/18 "2019-06-18T08:00:40Z")

</div>

> [@pmusaraj](#):
>
> rom core, and replace the symbol tags in it with yours, and see if that works.

I copied the same exact thing and GitHub declined it. So I tried a different technique using local CDN:  
[https://github.com/FortAwesome/Font-Awesome/wiki/Customize-Font-Awesome#with-localcdn-fontawesomealljs](https://github.com/FortAwesome/Font-Awesome/wiki/Customize-Font-Awesome#with-localcdn-fontawesomealljs)  
But it seems like there’s an error with the FA library. Here’s my broken code:

```plaintext
<script type="text/discourse-plugin" version="0.8">
    // replace 1568, 1568 with your SVG viewbox
// e001 is the unicode point which represents this custom icon. Increment this value for other icons
// replace 'M256...' with your single-path SVG
var faListOldStyle = {
  prefix: 'fas',
  iconName: 'oldm',
  icon: [1792, 1792, [], 'e001', 'M1344 960v-640h-448v1137q119-63 213-137 235-184 235-360zm192-768v768q0 86-33.5 170.5t-83 150-118 127.5-126.5 103-121 77.5-89.5 49.5-42.5 20q-12 6-26 6t-26-6q-16-7-42.5-20t-89.5-49.5-121-77.5-126.5-103-118-127.5-83-150-33.5-170.5v-768q0-26 19-45t45-19h1152q26 0 45 19t19 45z']
}
FontAwesome.library.add(
  faListOldStyle
)
</script>
<script type="text/discourse-plugin" version="0.8">
    api.replaceIcon('shield-alt', 'fas-olm');
</script>

```

This seems to be broken:

```plaintext
FontAwesome.library.add(
  faListOldStyle
)

```

Returning the following error:

```plaintext
2742f8c……020da268e4465.js:11 Uncaught ReferenceError: FontAwesome is not defined
    at 2742f8c……020da268e4465.js:11
(anonymous)	@	2742f8c……020da268e4465.js:11

```

Edit: I looked over your post here, and it worked! Thank you so much for guiding me on this tiny thing! 🙂  
 ![53%20PM](https://global.discourse-cdn.com/meta/original/3X/3/9/39f972be6507f721a92e577e47a9d16fe5451385.png)

> [@pmusaraj](#):
>
> o declare the XML encoding at the top of the file. Copy the contents of [https://raw.githubusercontent.com/discourse/discourse/master/vendor/assets/svg-icons/discourse-additional.svg](https://raw.githubusercontent.com/discourse/discourse/master/vendor/assets/svg-icons/discourse-additional.svg) from core, and replace the symbol tags in it with yours, and see if that works.
