Speed up WordPress admin with functions.php tweaks

Make the WordPress admin lighter with a few functions.php tweaks

A default admin loads things that a busy team rarely uses: dashboard widgets with WordPress news and a quick draft box, the emoji scripts, and the Heartbeat API that keeps sending requests to admin-ajax.php while a tab is open. None of them is needed for the admin to work, and on cheap hosting the Heartbeat requests of several open tabs can add real load.

Problem: The dashboard shows widgets nobody reads, and open admin tabs keep sending Heartbeat requests to the server.

Solution: Remove dashboard widgets on wp_dashboard_setup, remove the emoji scripts, and slow down the Heartbeat with the heartbeat_settings filter instead of disabling it.

Dashboard widgets

<?php
add_action( 'wp_dashboard_setup', function () {
    remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );       // WordPress Events and News
    remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );   // Quick Draft
    remove_meta_box( 'dashboard_site_health', 'dashboard', 'normal' ); // Site Health Status
} );

The news widget loads external feeds; Quick Draft and Activity run their own queries. Remove only what the team does not use: users can also hide widgets themselves in Screen Options.

Emoji scripts

Since WordPress 4.2 a small script on every page (and in the admin) checks whether the browser can show emoji and loads a polyfill if not. Current browsers can, so on most sites it is not needed:

<?php
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );

The details of removing core hooks, and why the priority 7 matters, are in removing actions and filters.

Heartbeat

The Heartbeat API keeps post locks (who is editing a post), shows the “you have been logged out” dialog and saves autosaves. On the post edit screen it runs every 15 seconds, on other admin screens every 60 seconds, and slower when the tab is in the background. Slowing it down keeps all features:

<?php
add_filter( 'heartbeat_settings', function ( $settings ) {
    $settings['interval'] = 60; // seconds
    return $settings;
} );

Disabling it completely (wp_deregister_script( 'heartbeat' )) also removes post locking and the session expiry warning: two editors can then overwrite each other’s work without a warning. Autosave itself uses a separate timer, but the locking and the login check are lost.

Measuring

Open the browser’s network panel on a post edit screen and filter by admin-ajax.php: with the default, a request every 15 seconds; with the filter, one per minute. On the server, the access log shows the same.

NOTE: These tweaks make the admin a little calmer, but they rarely fix a really slow admin. If the dashboard takes seconds to load, the cause is usually a plugin running heavy queries or remote requests on every admin page; the Query Monitor plugin shows which one.