Skip to content

Instantly share code, notes, and snippets.

@ryelle
Created December 3, 2013 16:56
Show Gist options
  • Save ryelle/7772839 to your computer and use it in GitHub Desktop.
Save ryelle/7772839 to your computer and use it in GitHub Desktop.
Set up a fake menu item to test using an icon font.
<?php
/**
* Plugin Name: Admin Icon Example
*/
// Add the fake menu item
add_action( 'admin_menu', 'admin_fake_menu_item' );
function admin_fake_menu_item() {
add_menu_page( 'Icon Test', 'Icon Test', 'edit_posts', 'admin-icon-font', '__return_true' );
}
add_action( 'admin_head', 'set_custom_font_icon' );
function set_custom_font_icon() {
?>
<style type="text/css">
/* for top level menu pages replace `{menu-slug}` with the slug name passed to `add_menu_page()` */
#toplevel_page_admin-icon-font .wp-menu-image:before {
font-family: FontAwesome !important;
content: '\f00d' !important;
}
</style>
<?php
}
// enqueue custom icon font
add_action( 'admin_enqueue_scripts', 'enqueue_font_awesome' );
function enqueue_font_awesome() {
wp_enqueue_style( 'font-awesome', '//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css', false, null );
}
@kstmasa
Copy link

kstmasa commented Mar 31, 2017

thank you a lot.
this code is really practical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment