Created
July 8, 2019 16:14
-
-
Save morgyface/831b7a2a9b0162ffc6a0de65029f2bba to your computer and use it in GitHub Desktop.
WordPress | Remove crap function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function remove_crap() { | |
| /** | |
| * This function removes redundant and unnecessary tags and scripts from | |
| * the head section of the site, a lot of this stuff is useful for blogs | |
| * but, generally, not utilised for a typical business website. | |
| * Whilst there is not necessarily a load-time advantage we might as well | |
| * keep the front-end tidy by removing everything we know is not required. | |
| * This function is hooked into the after_setup_theme hook, | |
| * which runs before the init hook. | |
| */ | |
| // Disable REST API link tag | |
| // Allows interaction remotely by sending and receiving JSON objects. | |
| remove_action('wp_head', 'rest_output_link_wp_head', 10); | |
| // Disable oEmbed Discovery Links | |
| // Allows an embedded representation of a URL on third party sites | |
| remove_action('wp_head', 'wp_oembed_add_discovery_links', 10); | |
| // Remove the link to the Really Simple Discovery service endpoint | |
| // An XML format and publishing convention for making posts discoverable | |
| remove_action( 'wp_head', 'rsd_link' ); | |
| // Removes the canonical url in the head | |
| // Would tell search engines that similar URLs are the same | |
| remove_action('wp_head', 'rel_canonical'); | |
| // Removes the shortlink URL in head | |
| // Nothing but the shorter version of the post or page url | |
| remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); | |
| // Prevents display of the XHTML generator that is created at wp_head hook | |
| // Would make the WordPress version visible and public | |
| remove_action( 'wp_head', 'wp_generator' ); | |
| // Removes link to info on how Windows Live Writer can talk to WordPress | |
| remove_action( 'wp_head', 'wlwmanifest_link' ); | |
| // Disables Emoji following autmoatic inclusion in v4.2. | |
| remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); | |
| remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
| } | |
| add_action( 'after_setup_theme', 'remove_crap' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment