Last active
August 10, 2024 02:25
-
-
Save Auke1810/f2a4cf04f2c07c74a393a4b442f22267 to your computer and use it in GitHub Desktop.
create a clean wordpress header and remove unnecessary clutter.
This file contains 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 | |
/* | |
Plugin Name: wordpress assist clean header | |
Plugin URI: http://www.wordpressassist.nl/ | |
Description: Remove shortlink hook | |
Version: 1.0 | |
Author: AukeJomm | |
Author URI: http://www.aukejongbloed.nl | |
*/ | |
remove_action('wp_head', 'rsd_link'); // remove really simple discovery link | |
remove_action('wp_head', 'wp_generator'); // remove wordpress version | |
remove_action('wp_head', 'feed_links', 2); // remove rss feed links (make sure you add them in yourself if youre using feedblitz or an rss service) | |
remove_action('wp_head', 'feed_links_extra', 3); // removes all extra rss feed links | |
remove_action('wp_head', 'index_rel_link'); // remove link to index page | |
remove_action('wp_head', 'wlwmanifest_link'); // remove wlwmanifest.xml (needed to support windows live writer) | |
remove_action('wp_head', 'start_post_rel_link', 10, 0); // remove random post link | |
remove_action('wp_head', 'parent_post_rel_link', 10, 0); // remove parent post link | |
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // remove the next and previous post links | |
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); | |
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); | |
remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); // Remove shortlink | |
/* | |
* Remove JSON API links in header html | |
*/ | |
function remove_json_api () { | |
// Remove the REST API lines from the HTML Header | |
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 ); | |
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 ); | |
// Remove the REST API endpoint. | |
remove_action( 'rest_api_init', 'wp_oembed_register_route' ); | |
// Turn off oEmbed auto discovery. | |
add_filter( 'embed_oembed_discover', '__return_false' ); | |
// Don't filter oEmbed results. | |
remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 ); | |
// Remove oEmbed discovery links. | |
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); | |
// Remove oEmbed-specific JavaScript from the front-end and back-end. | |
remove_action( 'wp_head', 'wp_oembed_add_host_js' ); | |
// Remove all embeds rewrite rules. | |
add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' ); | |
} | |
add_action( 'after_setup_theme', 'remove_json_api' ); | |
/* | |
Snippet completely disable the REST API and shows {"code":"rest_disabled","message":"The REST API is disabled on this site."} | |
when visiting http://yoursite.com/wp-json/ | |
*/ | |
function disable_json_api () { | |
// Filters for WP-API version 1.x | |
add_filter('json_enabled', '__return_false'); | |
add_filter('json_jsonp_enabled', '__return_false'); | |
// Filters for WP-API version 2.x | |
add_filter('rest_enabled', '__return_false'); | |
add_filter('rest_jsonp_enabled', '__return_false'); | |
} | |
add_action( 'after_setup_theme', 'disable_json_api' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wlwmanifest_link
is deprecated in 6.3.0 and no longer included in core so it might be redundant to add.