问题描述
任何人都可以识别当前的 Wordpress 后端,但我不想要。我想使用自己的设计改变它,我想为我的用户提供一个无缝的导航体验。如何更改仪表板的外观?我 google 了很多帖子和问题,似乎你只能改变大多数东西的 CSS,有些人正在使用钩子来添加自己的代码,而不是。
最佳解决方案
我使用我创建的自定义包含文件来修改仪表板。默认情况下,某些挂钩和过滤器被注释掉,但大多数东西都是在这里删除菜单,更改 wp 标志,删除元框,删除仪表板小工具等…
<?php
/*
File: cleanup-dashboard.php
Description: Clean up and customize the dashboard
Author: Chris Olbekson
Author URI: http://c3mdigital.com
*/
//Dashboard Action Hooks
add_action( 'admin_init', 'c3m_admin_style' );
add_action( 'admin_init', 'c3m_remove_dashboard_meta' );
add_action( 'admin_init', 'c3m_remove_post_meta' );
add_action( 'admin_menu', 'c3m_remove_admin_menus' );
add_action( 'admin_menu', 'c3m_remove_admin_submenus' );
add_filter( 'admin_user_info_links', 'c3m_user_greeting' );
add_action( 'admin_head', 'c3m_custom_logo' );
add_action( 'login_head', 'c3m_custom_login_css' );
add_action( 'login_head', 'c3m_custom_login_logo' );
add_filter( 'admin_footer_text', 'c3m_remove_footer_admin' );
add_action( 'init', 'c3m_change_post_object_label' );
add_action( 'admin_menu', 'c3m_change_post_menu_label' );
add_filter( 'admin_body_class', 'c3m_admin_body_class' );
//Dashboard CSS
function c3m_admin_style() {
wp_enqueue_style( 'c3m_admin_css', get_bloginfo( 'stylesheet_directory' ) . '/_/admin/c3m-admin.css', false, '1.0', 'all');
}
//Removes the dashboard widgets
function c3m_remove_dashboard_meta() {
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal');
remove_meta_box('dashboard_plugins', 'dashboard', 'normal');
remove_meta_box('dashboard_primary', 'dashboard', 'normal');
remove_meta_box('dashboard_secondary', 'dashboard', 'normal');
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal');
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
// remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
}
function c3m_remove_post_meta() {
// remove_meta_box( 'commentstatusdiv', 'page', 'normal' );
// remove_meta_box( 'commentstatusdiv', 'post', 'normal' );
// remove_meta_box( 'commentsdiv', 'page', 'normal' );
// remove_meta_box( 'commentsdiv', 'post', 'normal' );
// remove_meta_box( 'authordiv', 'page', 'normal' );
// remove_meta_box( 'authordiv', 'post', 'normal' );
// remove_meta_box( 'trackbacksdiv', 'post', 'normal' );
// remove_meta_box( 'trackbacksdiv', 'page', 'normal' );
// remove_meta_box( 'postcustom', 'post', 'normal' );
// remove_meta_box( 'postcustom', 'page', 'normal' );
// remove_meta_box( 'slugdiv', 'post', 'normal' );
// remove_meta_box( 'slugdiv', 'page', 'normal' );
//remove_meta_box( 'excerptdiv', 'post', 'normal' );
// remove_meta_box( 'page_choicediv', 'post', 'normal' );
// remove_meta_box( 'page_choicediv', 'sponsor_ad', 'normal' );
}
//Remove top level admin menus
//Remove top level admin menus
function c3m_remove_admin_menus() {
remove_menu_page( 'edit-comments.php' );
remove_menu_page( 'link-manager.php' );
remove_menu_page( 'tools.php' );
// remove_menu_page( 'plugins.php' );
// remove_menu_page( 'users.php' );
// remove_menu_page( 'options-general.php' );
}
//Remove sub level admin menus
function c3m_remove_admin_submenus() {
remove_submenu_page( 'themes.php', 'theme-editor.php' );
remove_submenu_page( 'themes.php', 'themes.php' );
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=post_tag' );
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=category' );
// remove_submenu_page( 'themes.php', 'nav-menus.php' );
// remove_submenu_page( 'themes.php', 'widgets.php' );
// remove_submenu_page( 'plugins.php', 'plugin-editor.php' );
// remove_submenu_page( 'plugins.php', 'plugin-install.php' );
// remove_submenu_page( 'users.php', 'users.php' );
// remove_submenu_page( 'users.php', 'user-new.php' );
// remove_submenu_page( 'options-general.php', 'options-writing.php' );
// remove_submenu_page( 'options-general.php', 'options-discussion.php' );
// remove_submenu_page( 'options-general.php', 'options-reading.php' );
// remove_submenu_page( 'options-general.php', 'options-discussion.php' );
// remove_submenu_page( 'options-general.php', 'options-media.php' );
// remove_submenu_page( 'options-general.php', 'options-privacy.php' );
// remove_submenu_page( 'options-general.php', 'options-permalinks.php' );
}
//This Adds an extra body class to a custom post type editor screen to target with css
function c3m_admin_body_class( $classes ) {
global $wpdb, $post;
$post_type = get_post_type( $post->ID );
if ( is_admin() && ( $post_type == 'sponsor_ad' ) ) {
$classes .= 'post_type-' . $post_type;
}
return $classes;
}
//Replaces Howdy with Welcome pretty self explanitory
function c3m_user_greeting( $greet_msg ) {
$greet_msg = str_replace( 'Howdy,','Welcome', $greet_msg);
return $greet_msg;
}
//Admin Header Logo this replaces the WordPress logo with your own
function c3m_custom_logo() {
echo '
<style type="text/css">
#header-logo { background-image: url('.get_bloginfo('template_directory').'/images/logo_wnd_small.png) !important; width:98px; }
</style>
';
}
//Admin Footer Logo Same as above but for the footer
function c3m_remove_footer_admin() {
echo '<div id="wlcms-footer-container">';
echo '<a target="_blank" href="http://c3mdigital.com"><img style="width:80px;" src="'.get_bloginfo('template_directory').'/images/developer-logo.png" id="wlcms-footer-logo">Custom WordPress Development</a>';
echo '</div><p id="safari-fix"';
}
//Login Screen CSS Custon css to replace the WP logo on the login screen
function c3m_custom_login_css() {
echo '<link rel="stylesheet" type="text/css" href="'.get_bloginfo('template_directory').'/_/admin/c3m-login.css" />';
}
//Login Screen Logo this incjects your logo css into the login css page
function c3m_custom_login_logo() {
echo '<style type="text/css">
h1 a { background-image:url('.get_bloginfo('template_directory').'/images/logo_wnd_new.png) !important; margin-bottom: 20px; height:100px; }
</style>
<script type="text/javascript">
function loginalt() {
var changeLink = document.getElementById('login').innerHTML;
changeLink = changeLink.replace("http://wordpress.org/", "' . site_url() . '");
changeLink = changeLink.replace("Powered by WordPress", "' . get_bloginfo('name') . '");
document.getElementById('login').innerHTML = changeLink;
}
window.onload=loginalt;
</script>
';
}
//This changes the name of Posts to something different
function c3m_change_post_menu_label() {
global $menu;
global $submenu;
$menu[5][0] = 'Post Boxes';
//$menu[10][0] = 'Files';
$submenu['edit.php'][5][0] = 'Post Boxes';
$submenu['edit.php'][10][0] = 'Add Post Box';
//$submenu['edit.php'][15][0] = 'Status';
echo '';
}
//Changes the label for the posts we changed above
function c3m_change_post_object_label() {
global $wp_post_types;
$labels = &$wp_post_types['post']->labels;
$labels->name = 'Post Boxes';
$labels->singular_name = 'Add New Post Box';
$labels->add_new = 'Add Post Box';
$labels->add_new_item = 'Add Post Box';
$labels->edit_item = 'Edit Post Box';
$labels->new_item = 'Post Box';
$labels->view_item = 'View Post Box';
$labels->search_items = 'Search Post Boxes';
$labels->not_found = 'No Post Boxes found';
$labels->not_found_in_trash = 'No Post Boxes found in Trash';
}
//Post Edit Columns Customizes the post edit columns by adding the featured image as a thumbnail and shows the excert
// Add to admin_init function
add_filter( 'manage_edit-post_columns', 'add_new_post_columns');
add_filter( 'manage_edit-post_columns', 'unset_the_defaults');
add_action( 'manage_posts_custom_column', 'testimonial_custom_column', 10, 2);
add_action( 'manage_posts_custom_column', 'testimonial_source_column', 10, 2);
function unset_the_defaults($defaults) {
unset($defaults['author']);
//unset($defaults['title']);
return $defaults;
}
function add_new_post_columns($dfaults) {
$dfaults['page_choice'] = 'Displayed On';
$dfaults['article_source'] = 'Source';
$dfaults['post_box_excerpt'] = 'Post Box Excerpt';
$dfaults['post_box_image'] = 'Post Box Image';
return $dfaults;
}
function testimonial_custom_column($column_name, $post_id){
$taxonomy = $column_name;
$post_type = get_post_type($post_id);
$terms = get_the_terms($post_id, $taxonomy);
if (!empty($terms) ) {
foreach ( $terms as $term )
$post_terms[] ="<a href='edit.php?post_type={$post_type}&{$taxonomy}={$term->slug}'> " .esc_html(sanitize_term_field('name', $term->name, $term->term_id, $taxonomy, 'edit')) . "</a>";
echo join('', $post_terms );
}
else echo '<i>No Display Page Set. </i>';
}
function testimonial_source_column($column_name, $post_id) {
global $post; global $prefix;
if ($column_name == 'article_source') {
echo get_post_meta($post_id, $prefix.'article-source', TRUE);
}
elseif ($column_name == 'post_box_image') {
if ( get_post_meta($post_id, $prefix.'post_box_image', TRUE) ) {
echo '<img src="'%20.get_post_meta($post_id,%20$prefix.'post_box_image',%20TRUE).%20'" style="max-width:40%; max-height:40%;" />';
}
else echo 'No Post Box Image Set';
}
elseif ($column_name == 'post_box_excerpt') echo substr($post->post_excerpt, 0, 150) . '...';
}
次佳解决方案
确实很少有关于如何自定义信息中心的信息。最近我也一直在寻找,并加上几个似乎有好的提示的书签。
你有看过这些线程吗?
参考文献
注:本文内容整合自 Google/Baidu/Bing 辅助翻译的英文资料结果。如果您对结果不满意,可以加入我们改善翻译效果:薇晓朵技术论坛。