WordPress 后台字体图标 Dashicons

追格官方小助手/ 2022年04月20日/ WordPress/ 浏览 1502

Dashicons 是WordPress官方维护的,用于后台管理的字体图标。虽然,数量不是很多,但对于一般的需求也足够用了。

可以在官方查看所有支持的Dashicons 图标:https://developer.wordpress.org/resource/dashicons/#menu

点击图标,就可以看到这个图标的代码,及使用方法等。



主要用法有三种:


1. register_post_type 注册新文章类型,在菜单中显示。


function wpdocs_create_post_type() {
    register_post_type( 'acme_product',
        array(
            'labels' => array(
                'name'          => __( 'Products', 'textdomain' ),
                'singular_name' => __( 'Product', 'textdomain' )
            ),
            'public'      => true,
            'has_archive' => true,
            'menu_icon'   => 'dashicons-products',
        )
    );
}
add_action( 'init', 'wpdocs_create_post_type', 0 );


2. 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'
    );
}


3. 在HTML中使用


<h2 class="dashicons-before dashicons-smiley">A Cheerful Headline</h2>


发表评论

暂无评论,抢个沙发...

客服 工单