Last active
October 21, 2022 02:38
-
-
Save robwent/5b413b6404137e718794 to your computer and use it in GitHub Desktop.
A collection of snippets for a Wordpress theme's function.php file to clean up the output
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 | |
/** | |
* Core output | |
**/ | |
//Remove the generator tag | |
remove_action('wp_head', 'wp_generator'); | |
//Remove the frontend admin bar while in development | |
add_filter('show_admin_bar', '__return_false'); | |
//Remove shortlinks from head | |
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); | |
//remove manifest link | |
//http://wpsmackdown.com/wordpress-cleanup-wp-head/ | |
remove_action('wp_head', 'wlwmanifest_link'); | |
remove_action('wp_head', 'rsd_link'); | |
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); | |
//Remove emoji frontend files added in 4.2 | |
remove_action('wp_head', 'print_emoji_detection_script', 7); | |
remove_action('wp_print_styles', 'print_emoji_styles'); | |
//Remove s.w.org prefetch link | |
add_filter( 'emoji_svg_url', '__return_false' ); | |
//Remove emoji admin files added in 4.2 - THIS CAN BREAK EDITOR FUNCTIONALITY | |
//remove_action('admin_print_scripts', 'print_emoji_detection_script'); | |
//remove_action('admin_print_styles', 'print_emoji_styles'); | |
//Disable the json api and remove the head link | |
add_filter('rest_enabled', '__return_false'); | |
add_filter('rest_jsonp_enabled', '__return_false'); | |
remove_action('wp_head', 'rest_output_link_wp_head', 10); | |
//oEmbed stuff | |
//Remove the REST API endpoint. | |
remove_action('rest_api_init', 'wp_oembed_register_route'); | |
//Turn off oEmbed auto discovery. | |
//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 the posts menu item if the site doesn't need a blog | |
//function post_remove () { | |
// remove_menu_page('edit.php'); | |
//} | |
//add_action('admin_menu', 'post_remove'); | |
//Also remove the new post and other links from the adminbar | |
//function remove_wp_nodes() { | |
// global $wp_admin_bar; | |
// $wp_admin_bar->remove_node( 'new-post' ); | |
// $wp_admin_bar->remove_node( 'new-link' ); | |
// $wp_admin_bar->remove_node( 'new-media' ); | |
//} | |
//add_action( 'admin_bar_menu', 'remove_wp_nodes', 999 ); | |
/** | |
* Third party extensions that do annoying things | |
**/ | |
//Remove All Yoast HTML Comments | |
//https://gist.github.com/paulcollett/4c81c4f6eb85334ba076 | |
function go_yoast() { | |
if (defined('WPSEO_VERSION')){ | |
add_action('get_header',function (){ ob_start(function ($o){ | |
return preg_replace('/\n?<.*?yoast.*?>/mi','',$o); }); }); | |
add_action('wp_head',function (){ ob_end_flush(); }, 999); | |
} | |
} | |
add_action('plugins_loaded', 'go_yoast'); | |
//Move the yoast seo stuff to the bottom of the admin pages | |
function yoasttobottom() { | |
return 'low'; | |
} | |
add_filter( 'wpseo_metabox_prio', 'yoasttobottom'); | |
//Remove WPML generator tag | |
if (!empty($GLOBALS['sitepress'])) { | |
add_action( 'wp_head', function() { | |
remove_action(current_filter(), array ($GLOBALS['sitepress'], 'meta_generator_tag')); | |
}, 0 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment