Skip to main content

Header Elements

warning

Large header images and heavy sliders are a common cause of poor LCP. Treat header elements as performance-critical.

Header Elements Explained

CapabilityWhat it enablesExample
Conditional headersDifferent headers per page typeBlog header vs landing page header
Hero sectionsHeadline + CTA + backgroundHomepage hero
Consistent brandingReusable header design tokensShared spacing/typography

Why It Matters

  • Headers appear on the most valuable pages (home, landing, archives).
  • Done well, they reduce template overrides and keep design consistent.
  • Done poorly, they dominate LCP and create CLS.

How It Works

Header Elements render conditionally based on rules and integrate with header hook points and theme layout regions.

flowchart TD
RULES[Header Element rules] -->|match| RENDER[Render header content]
RENDER --> HEADER[Header region]
HEADER --> PAGE[Page output]
RULES -->|no match| SKIP[No custom header]

Practical Walkthrough

Step 1: Find Header Hooks and Regions

find-header-hooks.sh
cd /var/www/html/wp-content/themes/generatepress
grep -R "do_action( 'generate_" -n inc/structure/header.php 2>/dev/null | head -n 80

Step 2: Audit Existing Elements (Optional)

audit-elements.sh
cd /var/www/html
wp post list --post_type=gp_elements --fields=ID,post_title,post_status --format=table 2>/dev/null || true
inspect-header-element-plugin-code.sh
cd /var/www/html
ls -lah wp-content/plugins/gp-premium/elements 2>/dev/null || true
grep -R "header" -n wp-content/plugins/gp-premium/elements 2>/dev/null | head -n 40

Practical Examples

Example 1: A Lightweight Hero Pattern

Hero content should be simple:

  • One primary heading (H1)
  • One supporting sentence
  • One CTA button
  • One optimized background image (optional)

Example 2: Archive Header

Use a Header Element for:

  • Category archives
  • Blog index
  • Custom post type archives

Keep the same spacing tokens so archives match pages.

Example 3: A Simple Hero Styling Pattern (CSS)

wp-content/themes/generatepress-child/assets/css/custom.css
.gp-hero {
padding: 64px 0;
background: linear-gradient(135deg, #0f172a, #1e3a8a);
color: #ffffff;
}

.gp-hero h1 { margin: 0 0 12px; line-height: 1.1; }
.gp-hero p { margin: 0 0 20px; max-width: 60ch; }

Example 4: Header Performance Checklist

CheckTargetWhy
Background image sizeas small as possibleLCP sensitive
Image dimensionsexplicitPrevent CLS
Font weightsminimalAvoid render delay
DOM depthshallowBetter INP

Best Practices

PracticeWhy
Optimize header imagesHeaders often dominate LCP
Use responsive imagesPrevents oversized downloads on mobile
Use one H1 per pageSEO and accessibility
Avoid autoplay slidersPerformance and UX
Use display rules narrowlyPrevent accidental global headers
Keep hero copy shortReduces layout complexity
Test on mobile firstHeaders often break on small screens

Troubleshooting

SymptomCauseFix
Header not showingRule mismatchStart with one page rule, then expand
Layout shiftsImage dimensions missingSet explicit sizes and use responsive images
Header duplicatesTwo elements target same pagesAudit inventory and disable one
Two H1s on the pageTitle + hero both H1Use one H1 and demote the other to H2/H3
Hero looks fine but slowHeavy image or fontOptimize assets and re-test with cache warmed

Hands-On

  1. Create a Header Element for one page only.
  2. Add a single optimized image and verify no CLS.
  3. Confirm you can disable the element and revert quickly.
  4. Capture the hero image file size from wp-content/uploads/ and document your budget.

Quick Reference

TaskCommand
Find header hooksgrep -R "do_action( 'generate_" -n inc/structure/header.php
List elementswp post list --post_type=gp_elements --fields=ID,post_title,post_status

What's Next