How to remove WordPress bloat without plugin

Last edited:
October 27, 2023
Reading time:
8 mins
Topic:
Bloat

/

Blog

/

Speed

/

How to remove WordPress b...

đź’ˇWe may earn a commision if you subscribe to a service from a link on this page.

WordPress is a powerful platform known for its flexibility and versatility, but it comes with a variety of features and functionalities that are enabled by default. While these features can be beneficial, not every website requires them, and in some cases, they can contribute to unnecessary bloat and slower performance. In this article, we’ll delve into how you can optimize your WordPress site by disabling unwanted features and filters. By doing so, you’ll not only improve the speed and performance of your site but also enhance its security and overall user experience.

Understanding the Benefits of Optimization

When you set up a WordPress website, you may not be aware of the numerous features that are automatically enabled. These features include various meta tags, scripts, and functionalities that cater to a broad range of needs. However, if your site doesn’t utilize them, they can become excess baggage, slowing down your website’s loading times and potentially affecting its search engine ranking.

Optimizing your WordPress site involves selectively disabling features and functionalities that are irrelevant to your specific requirements. By doing this, you reduce the amount of code that needs to load, resulting in faster page loading times. Improved speed not only enhances user experience but is also a crucial factor for SEO, as search engines favor faster-loading websites.

Removing Unwanted Features and Bloat

Adding Code to Your functions.php

First things first, to implement the provided code snippets and filters effectively while ensuring that your changes persist across WordPress theme updates, it’s imperative to use a child theme. Child themes act as an overlay to your main theme, allowing you to customize and add code without altering the original theme files. This approach is essential because changes made directly to the parent theme may be lost during updates.

To edit your child theme’s functions.php file, you have a few options. You can use the Theme Editor within your WordPress dashboard, access your hosting panel (e.g., cPanel) to modify files, or employ FTP (File Transfer Protocol) software. The Theme Editor provides a user-friendly interface for adding code directly within WordPress. Alternatively, using your hosting panel or FTP allows for more advanced control over your site’s files, which can be especially helpful when working with child themes.

By following these steps and placing your code snippets within a child theme’s functions.php file, you ensure that your WordPress optimizations not only enhance your website’s performance but also remain intact across theme updates, providing a seamless and improved experience for your site’s users. Let’s start with the coding.

Editing functions.php with an init Hook

Inside your child theme’s functions.php file, you should add the provided code snippets and filters within a custom function hooked to the init action. The init action is a crucial, automatically triggered hook in WordPress’s initialization process, ensuring that your customizations take effect at the right time, which is before the page loads. Here’s an example of how to structure a custom function with the init hook:

// Ensure the code runs during WordPress initialization
function customize_wordpress_wpr() {

// Add your code snippets and filters here
// For instance, you can remove unwanted features or make optimizations
 
}
add_action('init', 'customize_wordpress_wpr');

Make sure you include every code you copy from the next steps, inside the customize_wordpress_wpr() function.

1. Remove RSD Link

remove_action('wp_head', 'rsd_link');

The Really Simple Discovery (RSD) link is used for remote blog editing. If you don’t use this feature, removing it can help declutter your site.

2. Remove WordPress Generator

remove_action( 'wp_head', 'wp_generator' );

The WordPress Generator tag reveals your WordPress version. Removing it enhances security by not disclosing your site’s version.

3. Disable XML-RPC

add_filter('xmlrpc_enabled', '__return_false');
add_filter( 'pre_update_option_enable_xmlrpc', '__return_false' );
add_filter( 'pre_option_enable_xmlrpc', '__return_zero' );

XML-RPC enables external applications to interact with your site. Disabling it enhances security by reducing potential attack vectors.

4. Remove WLW Manifest Link

remove_action('wp_head', 'wlwmanifest_link');

This code removes the Windows Live Writer (WLW) Manifest link. If you don’t use WLW, you can safely remove this.

5. Remove Header Shortlink

remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);

The shortlink tag is used for sharing. If it’s not needed, you can remove it to simplify your site.

6. Remove Feed Links

remove_action('wp_head','feed_links_extra',3);
remove_action('wp_head','feed_links',2);

These actions remove feed links from your site’s head section. If you don’t use feeds, consider removing these.

7. Remove Emoji Script

remove_action('wp_head','print_emoji_detection_script',7);
remove_action('wp_print_styles','print_emoji_styles');

If your site doesn’t use Emojis, removing these scripts and styles can reduce HTTP requests and improve performance.

8. Remove REST Header Link

remove_action('wp_head', 'rest_output_link_wp_head');

This code hides the link to the REST API in the HTML head, improving security by not exposing the API endpoints.

9. Disable Template Redirect

remove_action( 'template_redirect', 'rest_output_link_header', 11);

Disabling REST API redirects ensures that REST API requests don’t trigger unnecessary redirects, which can impact performance.

10. Disable WooCommerce Inline Styles

remove_action( 'wp_footer', 'wp_enqueue_global_styles', 1 );
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );

If you want to customize WooCommerce styles to better fit your theme, consider disabling WooCommerce’s inline styles.

11. Disable WordPress SVG Styles

remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );

This action disables WordPress’s SVG styles. If you’re not using SVGs or want to handle the styles differently, this can optimize your site.

12. Disabling Post Publish via Email

If you don’t use the “Post Publish via Email” feature, you can disable it by adding the following code:

add_filter( 'enable_post_by_email_configuration', '__return_false' );

13. Enabling Classic Editor and Disabling Gutenberg

If you prefer the Classic Editor over Gutenberg, you can enable it and disable Gutenberg with the following code:

add_filter( 'use_block_editor_for_post', '__return_false' );

By following these steps, you can streamline your WordPress website, removing unnecessary elements and enhancing its performance. This optimization not only helps with a cleaner and more efficient dashboard but can also lead to faster page load times and a better user experience for your visitors.

Managing WordPress Heartbeat

Setting Heartbeat API Interval

function wp_heartbeat_settings_wpr( $settings ) {
// Anything between 15-120
$settings['interval'] = 119;
return $settings;
}
add_filter( 'heartbeat_settings', 'wp_heartbeat_settings_wpr' );

Adjusting the Heartbeat API interval can save server resources without significant drawbacks. Set it according to your site’s needs.

Removing Dashboard Welcome Cards

Remove Welcome Cards

function remove_dashboard_cards() {
// Remove Welcome panel
remove_action( 'welcome_panel', 'wp_welcome_panel' );
// Remove other dashboard widgets
remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
remove_meta_box( 'dashboard_site_health', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_activity', 'dashboard', 'normal');
}
add_action( 'wp_dashboard_setup', 'remove_dashboard_cards' );

If you find the dashboard welcome cards unnecessary, you can remove them to declutter your WordPress admin panel.

Wrapping Up

If you want to implement all above suggestions, the full code is the following:

// Ensure the code runs during WordPress initialization

function customize_wordpress_wpr() {

// Add your code snippets and filters here
remove_action('wp_head', 'rsd_link');
remove_action( 'wp_head', 'wp_generator' ) ;
add_filter('xmlrpc_enabled', '__return_false');
add_filter( 'pre_update_option_enable_xmlrpc', '__return_false' ); 
add_filter( 'pre_option_enable_xmlrpc', '__return_zero' );
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
remove_action('wp_head','feed_links_extra',3);
remove_action('wp_head','feed_links',2);
remove_action('wp_head','print_emoji_detection_script',7);
remove_action('wp_print_styles','print_emoji_styles');
add_filter('enable_post_by_email_configuration', '__return_false');
remove_action('wp_head', 'rest_output_link_wp_head');
remove_action( 'template_redirect', 'rest_output_link_header', 11);
add_filter('use_block_editor_for_post', '__return_false', 10);
remove_action( 'wp_footer', 'wp_enqueue_global_styles', 1 );
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
 
}
add_action('init', 'customize_wordpress_wpr');

By implementing these code snippets and filters, you can optimize your WordPress site, enhance security, and improve performance. However, exercise caution when making changes and ensure they don’t interfere with essential functionality. Customizing your WordPress site with code empowers you to tailor it to your unique needs and create a better user experience.

Remember that while these code snippets can enhance your WordPress site, it’s essential to keep your site and plugins updated for security and compatibility. Always back up your site before making significant changes and consider consulting a developer for complex customizations.