Wordpress Common Hooks
Hi,
I have developed an admin panel for Woo-commerce Developers http://wordpress.org/plugins/woocommerce-admin-theme-for-shop-manager/ by using various wordpress hooks.
So here are some general hooks and every WordPress Developer will need few of them.
Add these hooks in theme's functions.php.
Remove Update Notices in WordPress Admin Panel
hide WordPress version like we see meta ="generator" and WordPress version in view page source code
Disable the “please upgrade now” message in WordPress Admin Panel
Footer Content Change in WordPress Admin Panel
Enque custom style sheet for admin Panel in WordPress Admin Panel
Add custom menu in WordPress header in WordPress Admin Panel
To Replace Title href of Logo in Wordpress Admin Panel
To Replace Header Top Right Menus in Admin Panel
Remove Color Scheme in User Profile
Remove Unused Dashboard Widgets
Remove Biographical Info From Users Page
Remove Social Links In User Page in WordPress Admin Theme
Remove the `profile.php` Admin Color Scheme Options in WordPress Admin Theme
Hiding Upgrade Notices in WordPress Admin Theme
Remove Help tabs in WordPress Admin Theme
Remove Plugin's Update Notifications in WordPress Admin Theme
Hide WordPress Admin Bar Strip from the Website when Admin is logged in WordPress Admin Theme
Remove Welcome Message from WordPress Dashboard in WordPress Admin Theme
Change Admin Theme logo by the Website Logo in WordPress Admin Theme
Remove Junk From Head in Website View Source Code
Note: Add php opening tag after script closing tags Learn more »
I have developed an admin panel for Woo-commerce Developers http://wordpress.org/plugins/woocommerce-admin-theme-for-shop-manager/ by using various wordpress hooks.
So here are some general hooks and every WordPress Developer will need few of them.
Add these hooks in theme's functions.php.
Remove Update Notices in WordPress Admin Panel
add_action('admin_menu','wooadmin_balram');
function wooadmin_balram(){
remove_action( 'admin_notices', 'update_nag', 3 );
}
hide WordPress version like we see meta ="generator" and WordPress version in view page source code
remove_action('wp_head', 'wp_generator');
Disable the “please upgrade now” message in WordPress Admin Panel
add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
Footer Content Change in WordPress Admin Panel
add_filter('admin_footer_text', 'wooadmin_left_admin_footer_text_output', 11); //left side
function wooadmin_left_admin_footer_text_output($text) {
$text = bloginfo('name').' Admin Panel';
return $text;
}
add_filter('update_footer', 'wooadmin_right_admin_footer_text_output', 11); //right side
function wooadmin_right_admin_footer_text_output($text) {
$text = 'Version 1.0';
return $text;
}
Enque custom style sheet for admin Panel in WordPress Admin Panel
function wooadmin_my_admin_theme_style() {
wp_enqueue_style('my-admin-theme', plugins_url('wp-admin.css', __FILE__));
}
add_action('admin_enqueue_scripts', 'wooadmin_my_admin_theme_style');
add_action('login_enqueue_scripts', 'wooadmin_my_admin_theme_style');
Add custom menu in WordPress header in WordPress Admin Panel
function wooadmin_eshopbox_admin_bar() {
global $wp_admin_bar;
//Add a link called 'My Link'...
$wp_admin_bar->add_menu( array(
'id' => 'my-link',
'title' => 'My Link',
'href' => admin_url()
));
}
To Replace Title href of Logo in Wordpress Admin Panel
add_action( 'admin_head', 'wooadmin_eshop_admin_logo' );
function wooadmin_eshop_admin_logo()
{
if( function_exists('get_custom_header') ){
$width = get_custom_header()->width;
$height = get_custom_header()->height;
} else {
$width = HEADER_IMAGE_WIDTH;
$height = HEADER_IMAGE_HEIGHT;
}
?> // Do not Forget Add php open tag after closing script tag
}
To Replace Header Top Right Menus in Admin Panel
add_action( 'admin_head', 'wooadmin_eshop_header_right_menus' );
function wooadmin_eshop_header_right_menus()
{
?>
}
Remove Color Scheme in User Profile
function wooadmin_admin_color_scheme() {
global $_wp_admin_css_colors;
$_wp_admin_css_colors = 0;
}
add_action('admin_head', 'wooadmin_admin_color_scheme');
Remove Unused Dashboard Widgets
function wooadmin_remove_dashboard_widgets(){
remove_meta_box('posts', 'users', 'normal'); // Right Now
remove_meta_box('dashboard_right_now', 'dashboard', 'normal'); // Right Now
remove_meta_box('dashboard_browser_nag', 'dashboard', 'normal'); // Right Now
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal'); // Recent Comments
remove_meta_box('welcome-panel', 'dashboard', 'normal'); // Welcome Comments
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal'); // Incoming Links
remove_meta_box('dashboard_plugins', 'dashboard', 'normal'); // Plugins
remove_meta_box('dashboard_quick_press', 'dashboard', 'side'); // Quick Press
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side'); // Recent Drafts
remove_meta_box('dashboard_primary', 'dashboard', 'side'); // WordPress blog
remove_meta_box('dashboard_secondary', 'dashboard', 'side'); // Other WordPress News
// use 'dashboard-network' as the second parameter to remove widgets from a network dashboard.
}
add_action('wp_dashboard_setup', 'wooadmin_remove_dashboard_widgets');
Remove Biographical Info From Users Page
add_action( 'personal_options', array ( 'wooadmin_T5_Hide_Profile_Bio_Box', 'start' ) );
class wooadmin_T5_Hide_Profile_Bio_Box
{
/**
* Called on 'personal_options'.
*
* @return void
*/
public static function start()
{
$action = ( IS_PROFILE_PAGE ? 'show' : 'edit' ) . '_user_profile';
add_action( $action, array ( __CLASS__, 'stop' ) );
ob_start();
}
/**
* Strips the bio box from the buffered content.
*
* @return void
*/
public static function stop()
{
$html = ob_get_contents();
ob_end_clean();
// remove the headline
$headline = __( IS_PROFILE_PAGE ? 'About Yourself' : 'About the user' );
$html = str_replace( '' . $headline . '
', '', $html );
// remove the table row
$html = preg_replace( '~\s*Remove Social Links In User Page in WordPress Admin Theme
function wooadmin_remove_contactmethods($contactmethods ) {
unset($contactmethods['aim']);
unset($contactmethods['website']);
unset($contactmethods['yim']);
unset($contactmethods['jabber']);
unset($contactmethods['googleplus']);
unset($contactmethods['twitter']);
unset($contactmethods['url']);
return $contactmethods;
}
add_filter( 'user_contactmethods', 'wooadmin_remove_contactmethods' );
Remove the `profile.php` Admin Color Scheme Options in WordPress Admin Theme
remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
if ( ! function_exists( 'cor_remove_personal_options' ) ) {
// * Removes the leftover 'Visual Editor', 'Keyboard Shortcuts' and 'Toolbar' options
function cor_remove_personal_options( $subject ) {
$subject = preg_replace( '#Personal Options
.+?/table>#s', '', $subject, 1 );
return $subject;
}
function wooadmin_cor_profile_subject_start() {
ob_start( 'cor_remove_personal_options' );
}
function wooadmin_cor_profile_subject_end() {
ob_end_flush();
}
}
add_action( 'admin_head-profile.php', 'wooadmin_cor_profile_subject_start' );
add_action( 'admin_footer-profile.php', 'wooadmin_cor_profile_subject_end' );
Hiding Upgrade Notices in WordPress Admin Theme
add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
Remove Help tabs in WordPress Admin Theme
add_action('admin_head', 'wooadmin_mytheme_remove_help_tabs');
function wooadmin_mytheme_remove_help_tabs() {
$screen = get_current_screen();
$screen->remove_help_tabs();
remove_menu_page('edit-comments.php'); // Remove the Tools Menu
remove_menu_page('update-core.php'); // Remove the Tools Menu
}
Remove Plugin's Update Notifications in WordPress Admin Theme
remove_action( 'load-update-core.php', 'wp_update_plugins' ); add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
Hide WordPress Admin Bar Strip from the Website when Admin is logged in WordPress Admin Theme
add_filter('show_admin_bar', '__return_false');
Remove Welcome Message from WordPress Dashboard in WordPress Admin Theme
add_action( 'load-index.php', 'wooadmin_remove_welcome_panel' );
function wooadmin_remove_welcome_panel()
{
remove_action('welcome_panel', 'wp_welcome_panel');
$user_id = get_current_user_id();
if (0 !== get_user_meta( $user_id, 'show_welcome_panel', true ) ) {
update_user_meta( $user_id, 'show_welcome_panel', 0 );
}
}
Change Admin Theme logo by the Website Logo in WordPress Admin Theme
add_action( 'login_head', 'wooadmin_namespace_login_style1' );
function wooadmin_namespace_login_style1() {
if( function_exists('get_custom_header') ){
$width = get_custom_header()->width;
$height = get_custom_header()->height;
} else {
$width = HEADER_IMAGE_WIDTH;
$height = HEADER_IMAGE_HEIGHT;
}
echo ''.PHP_EOL;
}
function wooadmin_namespace_login_style() {
$url = plugins_url();
echo '';
}
Remove Junk From Head in Website View Source Code
function roots_head_cleanup() {
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
global $wp_widget_factory;
remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
add_filter('use_default_gallery_style', '__return_null');
}
add_action('init', 'roots_head_cleanup');
Note: Add php opening tag after script closing tags Learn more »