Ultimate Optimization Snippet for Classic Themes in WordPress

If you are running a Classic Theme with Classic Editor and have no intention of using Gutenberg, FSE, or block-based features, then WordPress is probably carrying a lot of unnecessary baggage on your site: Global Styles, block CSS, emoji scripts, embeds, RSS feeds, jQuery dependencies, and more. The snippet below is a consolidated optimization pack for classic websites, focusing on cleaning up both the admin area and the frontend output.

Ultimate Optimization Snippet for Classic Themes in WordPress

1. What does this snippet do?

  • Simplifies the admin interface by hiding unnecessary menus, widgets, help tabs, and admin bar items.
  • Optimizes the frontend for Classic Themes by disabling Gutenberg, Global Styles, block CSS, emojis, embeds, RSS feeds, and jQuery (if not needed).
  • Forces Classic Editor to use HTML mode by default.
  • Cleans up the <head> section by removing version tags, shortlinks, and legacy metadata.

This setup is designed for developers who fully control their theme and do not rely on WordPress as a visual page builder.

2. Classic Theme Optimization Snippet

Add the following code to your functions.php file (preferably in a child theme or a custom plugin):

<?php
/**
 * Classic Theme Optimization Pack
 * Comprehensive cleanup for admin UI and frontend output on classic WordPress sites.
 */

// ==================================================
// Admin UI Cleanup
// ==================================================

/**
 * Hide admin submenus (e.g., Dashboard > Updates)
 */
add_action('admin_menu', function () {
    remove_submenu_page('index.php', 'update-core.php');
}, 999);

/**
 * Remove Theme File Editor from the Appearance menu
 */
add_action('_admin_menu', function () {
    remove_action('admin_menu', '_add_themes_utility_last', 101);
}, 1);

/**
 * Disable autosave in the post editor
 */
add_action('wp_print_scripts', function () {
    if (is_admin()) {
        wp_deregister_script('autosave');
    }
});

/**
 * Remove help tabs from admin screens
 */
add_action('admin_head', function () {
    if (function_exists('get_current_screen')) {
        $screen = get_current_screen();
        if (method_exists($screen, 'remove_help_tabs')) {
            $screen->remove_help_tabs();
        }
    }
});

/**
 * Clean up the admin bar (remove WordPress logo and related links)
 */
add_action('wp_before_admin_bar_render', function () {
    global $wp_admin_bar;

    if (!is_admin_bar_showing() || !is_object($wp_admin_bar)) {
        return;
    }

    foreach (['wp-logo', 'wporg', 'documentation', 'support-forums', 'feedback'] as $id) {
        $wp_admin_bar->remove_menu($id);
    }
});

/**
 * Remove WordPress news widgets from the Dashboard
 */
add_action('admin_init', function () {
    remove_meta_box('dashboard_primary', 'dashboard', 'side');
    remove_meta_box('dashboard_secondary', 'dashboard', 'side');
});

/**
 * Customize the login page header and hide language switcher
 */
add_filter('login_headerurl', fn() => home_url());
add_filter('login_headertext', fn() => get_bloginfo('name'));
add_filter('login_display_language_dropdown', '__return_false');


// ==================================================
// Frontend Cleanup
// ==================================================

/**
 * Disable Nextend Social Login CSS/JS on frontend when the user is logged in
 */
add_action('wp', function () {
    if (is_user_logged_in() && !is_admin() && class_exists('NextendSocialLogin')) {
        remove_action('wp_head', ['NextendSocialLogin', 'styles'], 100);
        remove_action('wp_print_scripts', ['NextendSocialLogin', 'nslDOMReady']);
        remove_action('wp_print_footer_scripts', ['NextendSocialLogin', 'scripts'], 100);
    }
});

/**
 * Deregister jQuery on the frontend (only if your theme and plugins do not rely on it)
 */
add_action('wp_enqueue_scripts', function () {
    if (!is_admin()) {
        wp_deregister_script('jquery');
        wp_deregister_script('jquery-core');
        wp_deregister_script('jquery-migrate');
    }
}, 0);

/**
 * Disable WordPress emoji scripts and styles
 */
add_action('init', function () {
    $emoji_actions = [
        ['admin_print_styles', 'print_emoji_styles'],
        ['wp_head', 'print_emoji_detection_script', 7],
        ['admin_print_scripts', 'print_emoji_detection_script'],
        ['wp_print_styles', 'print_emoji_styles'],
    ];

    foreach ($emoji_actions as $a) {
        remove_action(...$a);
    }

    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_filter('tiny_mce_plugins', function ($plugins) {
        return is_array($plugins) ? array_diff($plugins, ['wpemoji']) : [];
    });
});

/**
 * Disable classic-theme-styles and intrinsic styles (WordPress 6.x)
 */
remove_action('wp_enqueue_scripts', 'wp_enqueue_classic_theme_styles');
add_action('wp_enqueue_scripts', function () {
    wp_dequeue_style('classic-theme-styles');
}, 20);

/**
 * Disable Gutenberg (block editor) for all post types
 */
add_filter('use_block_editor_for_post_type', '__return_false', 10);

/**
 * Remove block library CSS from the frontend
 */
add_action('wp_enqueue_scripts', function () {
    foreach (['wp-block-library', 'wp-block-library-theme', 'wc-block-style', 'storefront-gutenberg-blocks'] as $style) {
        wp_dequeue_style($style);
    }
}, 100);

/**
 * Remove WordPress version meta tag
 */
remove_action('wp_head', 'wp_generator');
add_filter('the_generator', '__return_empty_string');

/**
 * Optionally remove version query strings from scripts and styles
 * Uncomment only if you understand the cache implications.
 */
// add_filter('style_loader_src', 'init_manga_remove_ver', 9999);
// add_filter('script_loader_src', 'init_manga_remove_ver', 9999);
// function init_manga_remove_ver($src) {
//     return strpos($src, 'ver=') !== false ? remove_query_arg('ver', $src) : $src;
// }

/**
 * Disable all RSS/Atom feeds and redirect to homepage
 */
add_action('do_feed', 'init_manga_disable_feeds', -1);
add_action('do_feed_rdf', 'init_manga_disable_feeds', -1);
add_action('do_feed_rss', 'init_manga_disable_feeds', -1);
add_action('do_feed_rss2', 'init_manga_disable_feeds', -1);
add_action('do_feed_atom', 'init_manga_disable_feeds', -1);
add_action('do_feed_rss2_comments', 'init_manga_disable_feeds', -1);
add_action('do_feed_atom_comments', 'init_manga_disable_feeds', -1);

add_action('feed_links_show_posts_feed', '__return_false', -1);
add_action('feed_links_show_comments_feed', '__return_false', -1);

remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);

function init_manga_disable_feeds() {
    wp_redirect(home_url());
    exit;
}

/**
 * Disable oEmbed and related discovery features
 */
add_action('init', fn() => wp_deregister_script('wp-embed'));
remove_action('rest_api_init', 'wp_oembed_register_route');
add_filter('embed_oembed_discover', '__return_false');
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
remove_action('wp_head', 'wp_oembed_add_discovery_links');
remove_action('wp_head', 'wp_oembed_add_host_js');

/**
 * Remove block Global Styles CSS (handle: global-styles)
 */
add_action('wp_enqueue_scripts', fn() => wp_dequeue_style('global-styles'), 100);

/**
 * Default to HTML mode in Classic Editor
 */
add_filter('wp_default_editor', fn() => 'html');

/**
 * Remove legacy meta tags from <head>
 */
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);

/**
 * Remove Global Styles inline CSS (WordPress 6.9+)
 */
remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles');
remove_action('wp_footer', 'wp_enqueue_global_styles', 1);

3. Important Notes Before Using This

  • Do not use this with Block Themes or Full Site Editing: this snippet disables Gutenberg, block CSS, Global Styles, and classic-theme-styles. Block-based themes will break.
  • RSS is fully disabled: remove the feed section if your site depends on feeds for SEO, automation, or third-party integrations.
  • Be careful when disabling jQuery: only keep that part if you are absolutely sure your theme and plugins do not need it.
  • oEmbed is disabled: pasting plain YouTube or social media URLs will no longer auto-embed.
  • Autosave and help tabs: these can be useful for inexperienced editors. Remove those sections if needed.

4. Safe Deployment Strategy

  • Always apply this in a child theme or a custom plugin, never directly in a premium theme.
  • Test incrementally:
    • Check the admin area (editor, dashboard, admin bar).
    • Verify frontend features (forms, sliders, login, comments).
    • Inspect HTML source to confirm that Global Styles, block CSS, emoji, wp-embed, and feeds are truly removed.
  • If something breaks, comment out one section at a time (jQuery, embed, feeds) to isolate the cause.

Conclusion

For Classic Theme websites that do not rely on Gutenberg, centralizing all WordPress cleanup into a single optimization pack gives you full control over both the admin experience and the frontend output. Instead of installing multiple “disable-this” plugins, you explicitly decide what your site needs and what it does not. Less bloat, fewer hidden side effects, and a cleaner foundation for long-term maintenance.

Comments


  • No comments yet.

Init Toolbox

Press Ctrl + \ on desktop, or swipe left anywhere on mobile.

Login