Version 4.1.0 of Font Awesome has been released recently and it’s time for a refresher on how we can use icon fonts in WordPress.
To load Font Awesome, add the following in child theme’s functions.php:
// Load Font Awesome | |
add_action( 'wp_enqueue_scripts', 'enqueue_font_awesome' ); | |
function enqueue_font_awesome() { | |
wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css' ); | |
} |
Below are a few examples of using Font Awesome icons in various places.
Within content
In Page/Post editor when in Text mode,
<i class="fa fa-phone"></i> +91 1234567890 |
.fa-phone { | |
font-size: 25px; | |
vertical-align: middle; | |
padding-right: 5px; | |
} |
List of icons can be seen at http://fontawesome.io/icons/.
Nav menu items
.menu-primary li a:before { | |
font-family: FontAwesome; | |
padding-right: 7px; | |
/*font-style: normal; | |
font-weight: normal; | |
text-decoration: inherit;*/ | |
} | |
/* Home menu item */ | |
#menu-item-1616 a:before { | |
content: "\f015"; | |
} | |
/* Pages menu item */ | |
#menu-item-1413 a:before { | |
content: "\f0e8"; | |
} | |
/* Categories menu item */ | |
#menu-item-1414 a:before { | |
content: "\f15b"; | |
} |
Unicode values can be obtained by on the icon detail page.
Widget title
#meta-3 .widget-title:before { | |
font-family: FontAwesome; | |
padding-right: 7px; | |
content: "\f05a"; | |
font-style: normal; | |
font-weight: normal; | |
text-decoration: inherit; | |
} |
[…] Using Font Awesome and WordPress by Sridhar Katakam […]
I want to install the font awesome icons on my primary menu in the Eleven40 theme, into which file do I put this and the rest of the info?
.menu-primary li a:before {
font-family: FontAwesome;
padding-right: 7px;
/*font-style: normal;
font-weight: normal;
text-decoration: inherit;*/
You lost me on this one. Does it go in the menu.php file or the function.php?
Thanks
In child theme’s style.css.
OIC, thanks. Just went braindead on it
Hey Sridhar,
All your posts always have the fonts being enqueued which just adds to page load.
How would one load fonts using font-face?
It is possible to use an if conditional to load the fonts only on select pages (views) in your WordPress site.
Is there a way to add an icon to the site title ?
Thansk
Good Work Srikant and it can be used on any WordPress theme. Thanks for posting such a wonderful Tutorial for all the genesis lovers. Keep in touch
for some reason I can’t get this to work on a website i’m using locally with dynamik gen.
Icons just come up as X’s with boxes around them.
Not sure. I’ll double check link for cdn.
I’m an idiot. It was a misspelling with the css selector. Sorry. Works great. THanks.
We are using the Hueman theme within WordPress and I am unable to get the Stumbleupon and Trover icons to appear in the FOLLOW, the others work fine.
http://www.aholeinmyshoe.com
Steve Baker
Hi! i use your method and is the best, only one thing… i can’t see it in Firefox. You know why? thanks from spain
http://wpvkp.com/font-awesome-doesnt-display-in-firefox-maxcdn/
Heya!
Was wondering what your thoughts are on advantages/disadvantages to pasting CDN link in header vs. loading in function?
And what about loading stylesheet so that it doesn’t reflect specific version, but will load most recent ?
thnx!
-jennyb
Hi Sridhar,
You are the man! thanks for this wonderful tutorial. You have made every thing look easy with the examples. Now i’m able to use font awesome without any glitch. 🙂 🙂
Thanks for your detailed info about FA icons. Will you help me to setup custom wordpress blogroll with fontawesome icons?
Please reply
Hi Sridar,
Can you (or anyone else) tell me how I can prevent the icon from showing up in nav drop-downs but continue to display in the main menu item on nav bar?
Thanks!
Just a note: it’s recommended to load resources inside the theme, not from CDN.
Hi, I am using customizr theme in my wordpress website. I would like to see the FA icons instead of the “featured image”
Can you please help me
[…] http://sridharkatakam.com/using-font-awesome-wordpress/ http://premium.wpmudev.org/blog/wordpress-cu… http://premium.wpmudev.org/blog/add-icons-wordpress-menus/ […]
Hello, how would I add a font awesome down arrow such as &#f107 right aligned in an input text box, and to the right of the text “Search this website” ? Here’s the code:
//* Customize search form input box text
add_filter( ‘genesis_search_text’, ‘sp_search_text’ );
function sp_search_text( $text ) {
return esc_attr( ‘Search this website ‘ );
}
It is possible. Do you want that arrow to act as the search form submit button?
I have you and StudioPress to thank for finding the solution. 🙂
Put this in functions.php
//* Customize search form input box text
add_filter( ‘genesis_search_text’, ‘sp_search_text’ );
function sp_search_text( $text ) {
return esc_attr( Search this website …’ );
}
//* Customize search form input button text in order to add Font Awesome drop down arrow
add_filter( ‘genesis_search_button_text’, ‘sk_search_button_text’ );
function sk_search_button_text( $text ) {
return esc_attr( ‘’ );
}
Put this in style.css
.site-header .search-form {
position:relative;
}
.header-middle *::-moz-placeholder {
font-family: “myriad-pro-condensed”,sans-serif;
font-size:20px;
}
.header-middle input:focus {
font-family: “myriad-pro-condensed”,sans-serif;
font-size:20px;
}
.header-middle input[type=”submit”] {
border: 0;
color:#efe9dd;
display:inline-block;
font-family: ‘FontAwesome’;
font-size:20px;
padding:0;
background-color:transparent;
position: absolute;
left: 170px;
top:10px;
}
.header-middle input[type=”submit”]:focus {
border: 0;
color:#efe9dd;
padding:0;
background:none;
box-shadow:none;
font-size:20px;
}
The font awesome code is not showing up in the functions.php code above. In the parenthesis is ampersand#xf107;
[…] Using Font Awesome in WordPress […]
Thanks mate, helped me here http://p.bizanosa.com . Great job
[…] How to Enqueue Font Awesome […]
[…] Using Font Awesome in WordPress […]