【问题标题】:How do I change a default Dashicon in WordPress Admin area?如何更改 WordPress 管理区域中的默认 Dashicon?
【发布时间】:2021-09-26 02:58:24
【问题描述】:

因此,我将 WordPress 后端中的“帖子”重命名为“新闻”,并且能够使用添加到我的 functions.php 文件中的代码(感谢 Chris Perryman),但我还想将默认的破折号更改为很好:dashicons-media-document 而不是默认的“dashicons-admin-post”

我已尝试添加:$labels->icon_url = 'dashicons-media-document';,但由于某种原因这不起作用?

提前感谢您的帮助!

function revcon_change_post_label() {
    global $menu;
    global $submenu;
    $menu[5][0] = 'News';
    $submenu['edit.php'][5][0] = 'News';
    $submenu['edit.php'][10][0] = 'Add News';
    $submenu['edit.php'][16][0] = 'News Tags';
}
function revcon_change_post_object() {
    global $wp_post_types;
    $labels = &$wp_post_types['post']->labels;
    $labels->name = 'News';
    $labels->singular_name = 'News';
    $labels->add_new = 'Add News';
    $labels->add_new_item = 'Add News';
    $labels->edit_item = 'Edit News';
    $labels->new_item = 'News';
    $labels->view_item = 'View News';
    $labels->search_items = 'Search News';
    $labels->not_found = 'No News found';
    $labels->not_found_in_trash = 'No News found in Trash';
    $labels->all_items = 'All News';
    $labels->menu_name = 'News';
    $labels->name_admin_bar = 'News';
}
 
add_action( 'admin_menu', 'revcon_change_post_label' );
add_action( 'init', 'revcon_change_post_object' );

我希望能够在自定义主题的 function.php 中添加一两行简单的代码,以便在新安装时全部更新。

【问题讨论】:

    标签: php wordpress function custom-wordpress-pages dashicons


    【解决方案1】:

    使用 CSS

    function bks_replace_admin_menu_icons_css() {
        ?>
        <style>
            .dashicons-admin-post:before {
                font-family: "dashicons";
                content: "\f497" !important;
            }
        </style>
        <?php
    }
    
    add_action( 'admin_head', 'bks_replace_admin_menu_icons_css' );
    

    代码进入functions.php 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多