WordPress Admin Slowdown and External Resource Issues
Many WordPress site owners, especially beginners, may experience slow or sluggish loading in the admin dashboard. A common cause is that WordPress core, themes, or plugins load resources from external services like Google, such as Google Fonts, Google Maps API, or certain JavaScript libraries. Due to network connectivity issues, these external requests can cause significant page loading delays.
Solution: Filter External Resources via Code
You can remove or replace the loading of these external resources by adding filter functions to your theme's functions.php file. This is a lightweight optimization method that doesn't require installing additional plugins.
Core Code Implementation
Add the following code to the end of your active theme's functions.php file. It's recommended to back up the file before making changes.
// Block Google Fonts in the admin area
function wp_style_del_web( $src, $handle ) {
if ( strpos( strtolower( $src ), 'fonts.googleapis.com' ) !== false ) {
return '';
}
return $src;
}
add_filter( 'style_loader_src', 'wp_style_del_web', 10, 2 );
// Handle external resources in JavaScript
function wp_script_del_web( $src, $handle ) {
if ( empty( $src ) ) {
return $src;
}
$src_low = strtolower( $src );
// Replace Google Maps API with a local/alternative domain (Note: may be outdated)
if ( strpos( $src_low, 'maps.googleapis.com' ) !== false ) {
return str_replace( 'maps.googleapis.com', 'ditu.google.cn', $src_low );
}
// Replace Google AJAX library with a mirror (Note: service may be unstable)
if ( strpos( $src_low, 'ajax.googleapis.com' ) !== false ) {
return str_replace( 'ajax.googleapis.com', 'ajax.useso.com', $src_low );
}
// Remove certain social media scripts that may be inaccessible
if ( strpos( $src_low, 'twitter.com' ) !== false || strpos( $src_low, 'facebook.com' ) !== false || strpos( $src_low, 'youtube.com' ) !== false ) {
return '';
}
return $src;
}
add_filter( 'script_loader_src', 'wp_script_del_web', 10, 2 );
Code Explanation and Important Notes
- Function Purpose: The first function filters stylesheet (CSS) loading, specifically blocking Google Fonts. The second filters script (JS) loading, handling maps, AJAX libraries, and social media resources.
- Priority Parameter: The filter priority is set to the standard
10for better compatibility with other plugins. - Critical Reminders:
- The methods for replacing Google AJAX libraries and Maps may be outdated, as alternative services (like 360 mirror) might no longer work. Removing or replacing them could break functionality if your site relies on these services.
- A more modern and secure approach is to first check if your theme or plugin has an option to disable Google Fonts, or use an optimization plugin that offers local font loading.
- This code primarily affects resources loaded via WordPress core functions in both admin and frontend. Some plugins loading resources through other methods may not be filtered.
Usage Summary
- Access your WordPress site's file manager or connect via FTP.
- Navigate to
/wp-content/themes/your-theme-name/. - Find and edit the
functions.phpfile. - Copy and paste the full code above before the closing
?>tag (if present) or at the very end of the file. - Save the file and refresh your WordPress admin to check if loading speed improves.
Security Advice: Always create a full website backup or at least back up the
functions.phpfile before making any changes. If you encounter a white screen or errors after adding the code, revert the changes via FTP or restore from backup.