Cleaning up the WordPress Code
Clearing out the code
In your theme is a file called functions.php. This where all your sidebars and other features are set up.
Copy the following code into your functions.php:
function remheadlink() {
remove_action('wp_head','rsd_link');
remove_action('wp_head','wlwmanifest_link');
remove_action('wp_head','shortlink_wp_head');
remove_action('wp_head','wp_generator', 10,0 );
remove_action('wp_head','wp_shortlink_wp_head', 10, 0 );
remove_action('wp_head','start_post_rel_link', 10, 0 );
remove_action('wp_head','adjacent_posts_rel_link', 10, 0);
remove_action('wp_head','parent_post_rel_link', 10, 0 );
remove_action('wp_head','adjacent_posts_rel_link_wp_head', 10, 0 );
remove_action('wp_head','rel_canonical');
remove_action('wp_head','feed_links_extra', 3 );
remove_action('wp_head','feed_links', 2 );
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_scripts', 'print_emoji_detection_script' );
remove_action('admin_print_styles', 'print_emoji_styles' );
remove_action('wp_head', 'print_emoji_detection_script', 7 );
remove_action('wp_print_styles', 'print_emoji_styles' );
remove_action('admin_print_scripts', 'print_emoji_detection_script' );
remove_action('wp_print_styles', 'print_emoji_styles' );
remove_filter('wp_mail', 'wp_staticize_emoji_for_email' );
remove_filter('the_content_feed', 'wp_staticize_emoji' );
remove_filter('comment_text_rss', 'wp_staticize_emoji' ); }
add_action('init', 'remheadlink');
This will remove all sorts of unused code from your header.
Looking at the code for your menu you may see all sort of styles. Most of these aren’t needed but they are part of the WordPress core. Getting rid of them is simple.
Use the following code in your functions.php:
add_filter('nav_menu_css_class', 'themename_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'themename_attributes_filter', 100, 1);
add_filter('page_css_class', 'themename_attributes_filter', 100, 1);
Remembering to change ‘themename’ to your theme name.