Advertisement
alect

remove wp functions

Mar 1st, 2020
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: 小插件
  4. Plugin URI: https://blog.69cdn.com/disable-wordpress-unnecessary-functions/
  5. Description: 禁用一些毫无用处的功能
  6. Version: 0.1
  7. Author: alect
  8. */
  9. // Add custom Theme Functions here
  10.  
  11. // disable XML-RPC
  12. add_filter( 'xmlrpc_enabled', '__return_false' );
  13.  
  14. // remove RSD Links
  15. remove_action( 'wp_head', 'rsd_link' ) ;
  16.  
  17. // remove wlwmanifest Link
  18. remove_action('wp_head', 'wlwmanifest_link');
  19.  
  20. // remove version from head
  21. remove_action('wp_head', 'wp_generator');
  22.  
  23. // remove version from rss
  24. add_filter('the_generator', '__return_empty_string');
  25.  
  26. // remove version from head
  27. remove_action('wp_head', 'wp_generator');
  28.  
  29. // remove version from rss
  30. add_filter('the_generator', '__return_empty_string');
  31.  
  32. // remove version from scripts and styles
  33. function shapeSpace_remove_version_scripts_styles($src) {
  34. if (strpos($src, 'ver=')) {
  35. $src = remove_query_arg('ver', $src);
  36. }
  37. return $src;
  38. }
  39. add_filter('style_loader_src', 'shapeSpace_remove_version_scripts_styles', 9999);
  40. add_filter('script_loader_src', 'shapeSpace_remove_version_scripts_styles', 9999);
  41.  
  42. // Remove the Shortlink Tag
  43. add_filter('after_setup_theme', 'remove_redundant_shortlink');
  44. function remove_redundant_shortlink() {
  45. // remove HTML meta tag
  46. // <link rel='shortlink' href='http://example.com/?p=25' />
  47. remove_action('wp_head', 'wp_shortlink_wp_head', 10);
  48. // remove HTTP header
  49. // Link: <https://example.com/?p=25>; rel=shortlink
  50. remove_action( 'template_redirect', 'wp_shortlink_header', 11);
  51. }
  52.  
  53. // Disable Self Pingbacks
  54. function no_self_ping( &$links ) {
  55. $home = get_option( 'home' );
  56. foreach ( $links as $l => $link )
  57. if ( 0 === strpos( $link, $home ) )
  58. unset($links[$l]);
  59. }
  60.  
  61. add_action( 'pre_ping', 'no_self_ping' );
  62.  
  63. // Remove REST API Links
  64. add_action('after_setup_theme', function(){
  65. remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
  66. });
  67.  
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement