• About
  • Advertise
  • Privacy & Policy
  • Contact
djavupixel.com
  • Home
  • Design
    • Fonts
    • Icons
    • Logo
    • Photography
    • Wallpapers
  • Development
    • CSS
    • JS
    • Web
  • WordPress
  • Contact
No Result
View All Result
  • Home
  • Design
    • Fonts
    • Icons
    • Logo
    • Photography
    • Wallpapers
  • Development
    • CSS
    • JS
    • Web
  • WordPress
  • Contact
No Result
View All Result
djavupixel.com
No Result
View All Result
Home Apps Wordpress

Add Dashicons to your WordPress Plugin Admin Menu Icon

djavupixel by djavupixel
December 5, 2021
in Wordpress
432
0
1.4k
SHARES
4.4k
VIEWS
Share on FacebookShare on Twitter

Since WordPress 3.8 nice menu icons on dashboard appear beside different settings menu e.g. Posts, Pages, Media, Appearance etc. These icons do not use images but are build with CSS. If you are a WordPress plugin or theme developer, you can use these icons to have a nice icon for your product’s dashboard menu.

Admin menu items icons can only be added with register_post_type() and add_menu_page(). Both have an option to set an icon.

First you need to choose the icon you want to use: https://developer.wordpress.org/resource/dashicons/

Examples:
add_menu_page() accepts a parameter after the callback function for an icon URL, which can also accept a dashicons class. An example here below, replace dashicons-admin-media with the icons you selected before:

<?php
/**
* Register a menu page with a Dashicon.
*
* @see add_menu_page()
*/
function wpdocs_add_my_custom_menu() {
// Add an item to the menu.
add_menu_page (
__( 'My Page', 'textdomain' ),
__( 'My Title', 'textdomain' ),
'manage_options',
'my-page',
'my_admin_page_function',
'dashicons-admin-media',
);
}

// my_admin_page_function() displays the page content for the custom menu page
function my_admin_page_function() {
	if ( !current_user_can( 'manage_options' ) )  {
		wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
		//echo 'You do not have sufficient permissions to access this page.';
	}	
}

In register_post_type(), set menu_icon in the arguments array. Below an example

<?php 
/**
 * Register a menu page with a Dashicon.
 *
 * @see add_menu_page()
 */
function wpdocs_add_my_custom_menu() {
    // Add an item to the menu.
    add_menu_page (
        __( 'My Page', 'textdomain' ),
        __( 'My Title', 'textdomain' ),
        'manage_options',
        'my-page',
        'my_admin_page_function',
        'dashicons-admin-media',
    );
}

Tags: phpWordpress
Previous Post

Insert multiple rows via a PHP array into MYSQL

Next Post

Disable Gatekeeper in macOS Sierra

Next Post

Disable Gatekeeper in macOS Sierra

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • CSS
  • Design
  • Development
  • Fonts
  • Icons
  • JS
  • Logo
  • MacOS
  • Photography
  • Uncategorized
  • Wallpapers
  • Web
  • Wordpress

Tags

Air apple car Chrome city Coding communication Corporate Identity Cross Site Scriptings css Design e-Commerce Earth Extensions Free Google Gradient Styles grd Guideline Icons iPhone iPhone4 JavaScript jQuery Landscape Logo mac Nature Navigation osx Photography Photoshop php plugins PSD Sans-Serif security Serif setup SQL Injections Tutorial Water Wordpress WP e-Commerce xss
  • About
  • Advertise
  • Privacy & Policy
  • Contact

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Review
  • Apple
  • Applications
  • Computers
  • Gaming
  • Gear
    • Audio
    • Camera
    • Smartphone
  • Microsoft
  • Photography
  • Security

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.