LCP Priority Helper for Elementor
Reduces LCP render delay on Elementor sites by prioritizing the first image and preloading hero backgrounds and fonts—without changing content/SEO.
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/tombrian/lcpphe/archive/refs/heads/main.zipAuthor: Thomas Kamau (kamau.dev) Plugin site: https://github.com/TomBrian/LCPPHE
Reduce Largest Contentful Paint (LCP) delays on Elementor-powered WordPress sites without changing content or SEO. This plugin prioritizes the first above-the-fold media and preloads the hero background image and optional hero fonts.
Features
- First image on the page gets
loading="eager"andfetchpriority="high"(without duplicating existing attributes). - Disables lazy-loading for the first
imgoriframeinjected by core filters. - Detects Elementor hero background (first section/container with
background_background = classic) and injects<link rel="preload" as="image" fetchpriority="high">in<head>. - Responsive background support: prefers Mobile > Tablet > Desktop when enabled; optional fallback preload if different (cap 2 total).
- Optional font preloads: add up to 5 local
.woff2URLs via Settings → LCP Helper. - Optional preconnect to
fonts.gstatic.com(toggle off by default). - Front-end only; skips admin, feeds, REST, login, AJAX, CRON; does nothing on 404 or non-singular pages.
Requirements
- WordPress 5.9+
- PHP 7.4+
How it works
- Hooks
wp_get_attachment_image_attributesto setloading=eagerandfetchpriority=highfor the first attachment image only. - Hooks
wp_lazy_loading_enabledto disable lazy-loading for the firstimg/iframeonly. - On singular views, reads the current post’s
_elementor_data(JSON), DFS the node tree, and finds the first section/container with a classic background image. Resolves attachment IDs to URLs if present, and prints a single preload link (skips offsite URLs). - Prints font preloads in
<head>based on configured local.woff2URLs (if any). Optionally prints a preconnect tohttps://fonts.gstatic.com.
Settings (Settings → LCP Helper)
Go to Settings → LCP Helper:
- Preload mobile/tablet background intelligently (default ON)
- Also preload one fallback (tablet/desktop) if different (default ON)
- Affect iframes (default OFF)
- Font .woff2 URLs to Preload: up to 5 local paths, e.g.
/wp-content/uploads/fonts/hero-regular.woff2. - Enable preconnect to fonts.gstatic.com: toggle ON only if Google Fonts are used.
Known limitations
- Only the first hero background from Elementor is preloaded. Complex templates with multiple hero sections will only preload the first found.
- Only local
.woff2fonts are preloaded to avoid CORS and privacy issues. - The plugin does not alter page content or SEO; it only adjusts resource loading hints.
Must-Use (MU) plugin snippet (optional)
If you want to load this plugin as an MU plugin without activation, create wp-content/mu-plugins/lcp-priority-helper-loader.php with:
<?php
// MU loader for LCP Priority Helper for Elementor.
$plugin = WP_CONTENT_DIR . '/plugins/lcp-priority-helper/lcp-priority-helper.php';
if ( file_exists( $plugin ) ) {
include_once $plugin;
}
Adjust the path if the plugin is placed elsewhere.