{"id":4826,"date":"2025-08-14T13:26:20","date_gmt":"2025-08-14T11:26:20","guid":{"rendered":"https:\/\/wpmastertoolkit.com\/module\/head-sorter\/"},"modified":"2025-08-14T14:16:46","modified_gmt":"2025-08-14T12:16:46","slug":"head-sorter","status":"publish","type":"module","link":"https:\/\/wpmastertoolkit.com\/en\/module\/head-sorter\/","title":{"rendered":"Head Sorter"},"content":{"rendered":"<h1 class=\"wp-block-heading\">Head Sorter - Intelligent reorganization of the <code data-no-auto-translation=\"\">&lt;head&gt;<\/code> to boost speed and SEO<\/h1>\n\n\n\n<p>For many WordPress sites, the order of tags in the <code data-no-auto-translation=\"\">&lt;head&gt;<\/code> is silent chaos: metadata drowns out, CSS arrives too late, scripts block... The result: slower rendering, lower Web Vitals metrics and poorer SEO. The module <strong>Head Sorter<\/strong> from <strong>WPMasterToolKit<\/strong> has been created to put things in order automatically - without complicated settings - and put what really matters first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Which plug-in can the \"Head Sorter\" module replace?<\/h2>\n\n\n\n<p>In many cases, Head Sorter can replace small plugins dedicated to \"head tag sorting\", load order optimizations, or in-house snippets that attempt to manually move <code data-no-auto-translation=\"\">&lt;meta&gt;<\/code>, <code data-no-auto-translation=\"\">&lt;link&gt;<\/code> and <code data-no-auto-translation=\"\">&lt;script&gt;<\/code>. Here, everything is managed systematically and securely via an HTML parser.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How it works (in plain English)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Intercepting front-end rendering<\/strong><br>The module attaches to <code data-no-auto-translation=\"\">template_redirect<\/code> (priority <strong>-1000<\/strong>) to start a <strong>output buffer<\/strong> (output buffering). It does not <strong>that the Front-end<\/strong>.<\/li>\n\n\n\n<li><strong>HTML detection<\/strong><br>If the page does not contain <code data-no-auto-translation=\"\">&lt;\/html&gt;<\/code>the content remains unchanged.<\/li>\n\n\n\n<li><strong>Analysis of <code data-no-auto-translation=\"\">&lt;head&gt;<\/code> with DOMDocument<\/strong><br>The contents of the <code data-no-auto-translation=\"\">&lt;head&gt;<\/code> is loaded into a <strong>DOMDocument<\/strong> (with silent error handling), then <strong>all child tags are evaluated and sorted<\/strong> according to a <strong>weight<\/strong>.<\/li>\n\n\n\n<li><strong>Sort by importance<\/strong><br>Nodes (tags, text, comments) are assigned a weight. We <strong>re-inserts<\/strong> then the elements in the <code data-no-auto-translation=\"\">&lt;head&gt;<\/code> from most to least important, in <strong>preserving<\/strong> comments and texts.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">The priority grid (from most to least important)<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>META<\/strong> (10) : <code data-no-auto-translation=\"\">charset<\/code>, <code data-no-auto-translation=\"\">viewport<\/code>and some <code data-no-auto-translation=\"\">http-equiv<\/code> reviews (<code data-no-auto-translation=\"\">content-security-policy<\/code>, <code data-no-auto-translation=\"\">content-type<\/code>, <code data-no-auto-translation=\"\">default-style<\/code>etc.)<\/li>\n\n\n\n<li><strong>TITLE<\/strong> (9)<\/li>\n\n\n\n<li><strong>PRECONNECT<\/strong> (8) : <code data-no-auto-translation=\"\">&lt;link rel=\"preconnect\"&gt;<\/code><\/li>\n\n\n\n<li><strong>ASYNC_SCRIPT<\/strong> (7) : <code data-no-auto-translation=\"\">&lt;script src ... async&gt;<\/code><\/li>\n\n\n\n<li><strong>IMPORT_STYLES<\/strong> (6) : <code data-no-auto-translation=\"\">&lt;style&gt;<\/code> containing <code data-no-auto-translation=\"\">@import<\/code><\/li>\n\n\n\n<li><strong>SYNC_SCRIPT<\/strong> (5) : <code data-no-auto-translation=\"\">&lt;script&gt;<\/code> inline blocking (non <code data-no-auto-translation=\"\">defer<\/code>no <code data-no-auto-translation=\"\">async<\/code>no <code data-no-auto-translation=\"\">type=\"module\"<\/code>and no <code data-no-auto-translation=\"\">type<\/code> JSON)<\/li>\n\n\n\n<li><strong>SYNC_STYLES<\/strong> (4) : <code data-no-auto-translation=\"\">&lt;link rel=\"stylesheet\"&gt;<\/code> and <code data-no-auto-translation=\"\">&lt;style&gt;<\/code><\/li>\n\n\n\n<li><strong>PRELOAD<\/strong> (3) : <code data-no-auto-translation=\"\">&lt;link rel=\"preload|modulepreload\"&gt;<\/code><\/li>\n\n\n\n<li><strong>DEFER_SCRIPT<\/strong> (2) : <code data-no-auto-translation=\"\">&lt;script src ... defer&gt;<\/code> or <code data-no-auto-translation=\"\">&lt;script type=\"module\"&gt;<\/code> (without <code data-no-auto-translation=\"\">async<\/code>)<\/li>\n\n\n\n<li><strong>PREFETCH_PRERENDER<\/strong> (1) : <code data-no-auto-translation=\"\">&lt;link rel=\"prefetch|dns-prefetch|prerender\"&gt;<\/code><\/li>\n\n\n\n<li><strong>OTHER<\/strong> (0): everything else, including JSON scripts (<code data-no-auto-translation=\"\">application\/ld+json<\/code>etc.) and non-element nodes (texts, comments), which are kept<\/li>\n<\/ul>\n\n\n\n<p>\ud83d\udc49 In concrete terms, your <strong>critical tags (<code data-no-auto-translation=\"\">charset<\/code>, <code data-no-auto-translation=\"\">viewport<\/code>, <code data-no-auto-translation=\"\">title<\/code>) go to the top<\/strong>resources, followed by <strong>connection and CSS<\/strong> necessary for rendering, and blocking scripts are eliminated as far as possible by giving priority to <code data-no-auto-translation=\"\">async<\/code>\/<code data-no-auto-translation=\"\">defer<\/code>\/<code data-no-auto-translation=\"\">module<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why it's good for performance and SEO<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Faster FCP\/LCP<\/strong> essential meta and styles arrive early, reducing initial rendering time.<\/li>\n\n\n\n<li><strong>Less blocking JS<\/strong> scripts <code data-no-auto-translation=\"\">async\/defer\/module<\/code> are favored, reducing the impact on the critical rendering path.<\/li>\n\n\n\n<li><strong>Technical SEO<\/strong> one <code data-no-auto-translation=\"\">&lt;head&gt;<\/code> better structured helps engines to understand and index correctly (consistent title\/meta first).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Behaviors and compatibility to know<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Front-end only<\/strong> : hooked on <code data-no-auto-translation=\"\">template_redirect<\/code>. The admin is not impacted.<\/li>\n\n\n\n<li><strong>Content preservation<\/strong> comments and texts in the <code data-no-auto-translation=\"\">&lt;head&gt;<\/code> are retained.<\/li>\n\n\n\n<li><strong>JSON scripts<\/strong> (e.g. <code data-no-auto-translation=\"\">application\/ld+json<\/code>) : <strong>not treated as blocking scripts<\/strong> (\"OTHER\" weight) to avoid moving them aggressively.<\/li>\n\n\n\n<li><strong>ES modules<\/strong> (<code data-no-auto-translation=\"\">type=\"module\"<\/code>): treated as <strong>defer<\/strong> by default (good for rendering).<\/li>\n\n\n\n<li><strong>Ill-formed HTML<\/strong> DOMDocument can attempt to \"correct\" a badly structured head, but keep HTML clean for best results.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to use this module<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Activate the Head Sorter module<\/strong> in WPMasterToolKit.<\/li>\n\n\n\n<li><strong>Empty cache<\/strong> your plugins\/server\/CDN if you use them.<\/li>\n\n\n\n<li><strong>Control a page<\/strong> (home page, sample article) to check the order of the <code data-no-auto-translation=\"\">&lt;head&gt;<\/code> with the browser's dev tools.<\/li>\n\n\n\n<li>No adjustments to make: everything is <strong>automatic<\/strong>.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Our technical choices (and why)<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Output buffering<\/strong> at the earliest (<code data-no-auto-translation=\"\">template_redirect<\/code>priority -1000) to capture the final rendering of the page without touching the heart of WordPress or the themes.<\/li>\n\n\n\n<li><strong>DOMDocument<\/strong> for a <strong>reliable handling<\/strong> rather than fragile regexes.<\/li>\n\n\n\n<li><strong>Weight matrix<\/strong> clear and extensible code to prioritize :\n<ul class=\"wp-block-list\">\n<li><strong>Meta\/title<\/strong> first and foremost (web standards + SEO).<\/li>\n\n\n\n<li><strong>Preconnect\/Preload\/Style sheets<\/strong> before blocking scripts.<\/li>\n\n\n\n<li><strong><code data-no-auto-translation=\"\">async<\/code>\/<code data-no-auto-translation=\"\">defer<\/code>\/<code data-no-auto-translation=\"\">module<\/code><\/strong> better off than conventional synchronous scripts.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Conservatism on JSON<\/strong> : exclusion of <code data-no-auto-translation=\"\">type<\/code> containing <code data-no-auto-translation=\"\">json<\/code> from the \"synchronous script\" category to avoid affecting the markup of structured data.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Hooks and filters<\/h2>\n\n\n\n<p>This module <strong>exposes no <code data-no-auto-translation=\"\">apply_filters<\/code> or <code data-no-auto-translation=\"\">do_action<\/code> personalized<\/strong>. Behavior is entirely internal.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practical tips<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Avoid <code data-no-auto-translation=\"\">@import<\/code> in your <code data-no-auto-translation=\"\">&lt;style&gt;<\/code> : even if they have priority here, they remain <strong>slower<\/strong> that a <code data-no-auto-translation=\"\">&lt;link rel=\"stylesheet\"&gt;<\/code>.<\/li>\n\n\n\n<li>If a critical script needs to run early, prefer <strong><code data-no-auto-translation=\"\">defer<\/code><\/strong> (or <strong><code data-no-auto-translation=\"\">type=\"module\"<\/code><\/strong>) rather than synchronous, so as not to block rendering.<\/li>\n\n\n\n<li>Use <code data-no-auto-translation=\"\">rel=\"preconnect\"<\/code> and <code data-no-auto-translation=\"\">rel=\"preload\"<\/code> with parsimony and precision (preload only what is critical).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The module <strong>Head Sorter<\/strong> brings order to the <code data-no-auto-translation=\"\">&lt;head&gt;<\/code> of your WordPress site automatically, respecting good performance and technical SEO practices. Activate it, clear your caches, and enjoy cleaner, faster loading - without wasting time micromanaging tags.<\/p>","protected":false},"excerpt":{"rendered":"<p>WPMasterToolKit's Head Sorter module automatically optimizes the HTML header of your WordPress site by reorganizing the critical elements of the header. <head>. This improves page loading speed and SEO without the need for additional configuration. Using PHP's DOMDocument library, it prioritizes important tags, contributing to better performance and an enriched user experience.<\/p>","protected":false},"featured_media":0,"parent":0,"template":"","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","_surecart_dashboard_logo_width":"180px","_surecart_dashboard_show_logo":true,"_surecart_dashboard_navigation_orders":true,"_surecart_dashboard_navigation_invoices":true,"_surecart_dashboard_navigation_subscriptions":true,"_surecart_dashboard_navigation_downloads":true,"_surecart_dashboard_navigation_billing":true,"_surecart_dashboard_navigation_account":true},"class_list":["post-4826","module","type-module","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/wpmastertoolkit.com\/en\/wp-json\/wp\/v2\/module\/4826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmastertoolkit.com\/en\/wp-json\/wp\/v2\/module"}],"about":[{"href":"https:\/\/wpmastertoolkit.com\/en\/wp-json\/wp\/v2\/types\/module"}],"wp:attachment":[{"href":"https:\/\/wpmastertoolkit.com\/en\/wp-json\/wp\/v2\/media?parent=4826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}