2016-10-04

Most content management systems try to add as many features to their platforms as possible, and WordPress is certainly no exception to this rule. I like to choose my “features”, but disabling them from the dashboard is often not an option. Whether you want to minimize code bloat to improve performance, or tighten up security on your WordPress install, the following areas of WordPress’s head section are a good place to start.

You can pick and choose which of the following CSS, JS, and meta data you want to remove—I’ll leave that up to you—but I describe the purpose of each bit of fat we’re trimming from WordPress.

Removing a function you don’t want is often as simple as adding a few lines of code to the functions.php file of your (preferably child) theme’s directory. Skip the ‘How This Works’ section if you just want the code.

How it Works (Optional)

Remove Shortlinks Meta Data

Remove Rest API Meta Data

Remove WordPress Emojis

How it Works

Essentially, you’re using WordPress’s add_action() function to hook you’re own custom function goodbye_bloat, to WordPress’s action hook after_setup_theme.

Your custom function goodbye_bloat uses WordPress's remove_action function to prevent specific callbacks from loading with your theme.

The after_setup_theme action is a hook called during each page load after the theme is initialized. This ensures that the callback you are removing has been added before you try to remove it.

As you can see, you can remove more than one callback with your custom function. In the example above, we've removed two callbacks: the REST API link and Shortlink, and as a result, they'd won't appear in your source code.

If ever you need to re-enable a function, it's as simple as removing the functions or filters you added to functions.php. I do, however suggest that you add a comment above each function you disable, with a short description and date, to help you undo anything you want to at a later date.

Shortlinks Meta Data

WordPress 3 introduced its own flavour of URL shortener; Shortlinks, similar to bit.ly and TinyURL. If your hosting your site on WordPress.com, it might look something like wp.me/[string-here]; otherwise, the URL might simply use your page or post ID, and look something like example.com/?p=[id-here].

Source example:

Removal:

REST API Meta Data

WordPress 4.4 introduced an api.w.org meta link to let other sites and applications know that your site now supports the new JSON REST API.

Source example:

The following added to your theme's functions.php will remove the link from the WP header, but won't disable the REST API:

Removal:

The following will remove the meta data link from the head section of your pages:

If you'd like to also remove the API link from your HTTP headers, you can also add the following to the goodbye_bloat function:

If, for whatever reason, you do want to completely disable the REST API, you'd add the following to functions.php instead:

WordPress Emojis

In WordPress 4.2, native support was incorporated into WP core for emojis, which you can think of as a bigger, better version of smileys. Emojis can be a fun addition to certain types of blogs, but if you don't have a need for a thumbs up or a big grinning face on your site, you don't need the internal CSS and calls to JS that come with them.

Source example:

Internal JavaScript

Internal CSS

Removal:

Auto Embed Script

Introduced in WordPress 4.4, -->

The post How to Remove Code Bloat From WordPress Header appeared first on Springboard SEO Blog.

Show more