英文:
Remove WordPress admin icons or SVG's
问题
I am finding people are choosing Squarespace etc simply because the backend menu is less confusing. I love WordPress and would like to simplify the backend without a plugin.
我发现人们选择Squarespace等平台仅仅是因为后台菜单较为简单。我喜欢WordPress,并希望简化后台菜单,而不使用插件。
I am starting by trying to remove icons and SVG's added by plugins. I can remove Woocommerce, for example, by this code I found.
我开始尝试移除插件添加的图标和SVG图像。例如,我可以使用下面这段代码来移除Woocommerce。
add_action("admin_menu", function () {
foreach ($GLOBALS["menu"] as $position => $tab) {
if ("woocommerce" === $tab[2]) {
$GLOBALS["menu"][$position][6] = "";
break;
}
}
});
It's not ideal, and I'd like to use code to remove them in a cleaner fashion. I am aware there are plugins that do it, which makes me sure that it can be done programmatically, but my experience precludes me from knowing how.
这并不是最理想的方法,我想用更清晰的方式使用代码移除它们。我知道有一些插件可以做到这一点,这让我确信它可以以编程方式实现,但由于我的经验有限,我不知道如何做到这一点。
While this works for Woocommerce, I'd like to remove them all, as, while I'm sure at some stage it was trendy or cute, it would be nice if it was optional. I know that's a WordPress decision, but for now, does anyone have a workaround?
虽然这对于Woocommerce有效,但我想移除它们全部,因为尽管我确定在某个阶段这可能是时尚或可爱的,但如果它是可选的,那将是很好的。我知道这是WordPress的决定,但目前是否有人有解决方法?
英文:
I am finding people are choosing Squarespace etc simply because the backend menu is less confusing. I love WordPress and would like to simplify the backend without a plugin.
I am starting by trying to remove icons and SVG's added by plugins. I can remove Woocommerce for example by this code I found
add_action("admin_menu", function () {
foreach ($GLOBALS["menu"] as $position => $tab) {
if ("woocommerce" === $tab["2"]) {
$GLOBALS["menu"][$position][6] = "";
break;
}
}
});
It's not ideal, and l'd like to use code to remove them in a cleaner fashion, I am aware there are plugins that do it which makes me sure that it can be done programmatically but my experience precludes me from knowing how.
While this works for Woocommerce, I'd like to remove them all as whilst I'm sure at some stage it was trendy or cute it would be nice if it was optional, I know that's a WordPress decision, but for now does anyone have a work around?
答案1
得分: 0
我解决了。希望对其他人有所帮助。
提供的代码包含两个函数:remove_admin_menu_images和align_admin_menu_text。第一个函数移除默认的管理菜单图像和颜色方案,而第二个函数调整管理菜单文本的对齐方式。
在align_admin_menu_text函数中的样式代码直接嵌入在代码本身中,不需要外部来源。
function remove_admin_menu_images() {
remove_action('admin_head', 'wp_admin_css'); // 移除默认管理菜单图像
remove_action('admin_head', 'wp_admin_css_color'); // 移除默认管理菜单颜色方案
}
add_action('admin_menu', 'remove_admin_menu_images');
function align_admin_menu_text() {
echo '<style>
#adminmenu .wp-menu-image { display: none !important; } /* 隐藏菜单图标 */
#adminmenu .wp-menu-name { padding-left: 20px !important; } /* 调整文本对齐方式 */
</style>';
}
add_action('admin_head', 'align_admin_menu_text');
英文:
I worked it out. I hope it helps someone else.
The code provided contains two functions: remove_admin_menu_images and align_admin_menu_text. The first function removes the default admin menu images and color scheme, while the second function adjusts the alignment of the admin menu text.
The styling code within the align_admin_menu_text function is directly embedded in the code itself and does not require an external source.
function remove_admin_menu_images() {
remove_action('admin_head', 'wp_admin_css'); // Remove default admin menu images
remove_action('admin_head', 'wp_admin_css_color'); // Remove default admin menu color scheme
}
add_action('admin_menu', 'remove_admin_menu_images');
function align_admin_menu_text() {
echo '<style>
#adminmenu .wp-menu-image { display: none !important; } /* Hide menu icons */
#adminmenu .wp-menu-name { padding-left: 20px !important; } /* Adjust text alignment */
</style>';
}
add_action('admin_head', 'align_admin_menu_text');
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论