Skip to main content

Global Layout Framework

warning

Template overrides are a last resort. Prefer hooks/filters first to keep future GeneratePress updates painless.

Global Layout Framework Explained

LayerWhat it controlsPrimary locations
Structure functionsBuilds header/footer/sidebar/container markup/wp-content/themes/generatepress/inc/structure/
TemplatesWordPress template hierarchy entry points/wp-content/themes/generatepress/templates/
Layout settingsContainer width, sidebars, padding, alignmentCustomizer + defaults + filters
Hook pointsInjection points around structural regionsdo_action( 'generate_*' ) in structure/templates

Why It Matters

  • Layout work is where most sites diverge: full-width landing pages, no-sidebars, sticky headers, custom hero sections.
  • GeneratePress makes layout changes update-safe by exposing hook points and filters around each region.
  • When you know which file owns a region, you can debug faster (and avoid "random CSS" fixes).

How It Works

Templates call structural functions. Structural functions print markup and fire hook points. Filters decide layouts based on Customizer values and request context.

flowchart TD
TPL[templates/*.php] --> STRUCT[inc/structure/*.php]
STRUCT --> HOOKS[generate_* actions]
STRUCT --> FILTERS[generate_* filters]
FILTERS --> SETTINGS[(Customizer theme mods)]
HOOKS --> CHILD[Child theme callbacks]

Practical Walkthrough

Step 1: Identify the Structure Files

list-structure-files.sh
cd /var/www/html/wp-content/themes/generatepress
ls inc/structure
search-layout-filters.sh
cd /var/www/html/wp-content/themes/generatepress
grep -R "apply_filters( 'generate_" -n inc/structure inc | head -n 40

Step 3: Find Hook Points Around Content and Sidebars

search-hook-points.sh
cd /var/www/html/wp-content/themes/generatepress
grep -R "do_action( 'generate_" -n inc/structure templates | head -n 40

Step 4: Locate the Markup Wrappers You Will Style

find-common-wrapper-classes.sh
cd /var/www/html/wp-content/themes/generatepress
grep -R "site-content\|inside-\|content-area\|main\b" -n templates inc/structure | head -n 40

Practical Examples

Example 1: Force No Sidebar on a Specific Page (Child Theme)

Create a small filter in your child theme functions.php:

wp-content/themes/generatepress-child/functions.php
<?php

add_filter( 'generate_sidebar_layout', function( $layout ) {
if ( is_page( 'landing' ) ) {
return 'no-sidebar';
}

return $layout;
} );

Notes:

  • Keep conditionals narrow (specific page slug, template, or post type).
  • Test logged-out to avoid admin-only behavior differences.

Example 2: Add a Lightweight "Above Content" Banner

wp-content/themes/generatepress-child/functions.php
<?php

add_action( 'generate_before_main_content', function() {
if ( is_singular() ) {
echo '<div class="gp-banner">Maintenance window: Sunday 02:00 UTC</div>';
}
} );
caution

If you output HTML, escape dynamic values and keep markup minimal. Extra DOM wrappers affect CLS/INP.

Best Practices

Best practiceWhy
Use filters for layout decisionsLayout should be deterministic and easy to audit
Use actions for markup injectionsKeeps structure changes localized
Keep CSS changes close to the componentAvoid global overrides that regress other pages
Measure impact (CLS/INP/LCP)Layout tweaks often have performance side effects

Troubleshooting

IssueCauseFix
Sidebar still showsFilter returns wrong layout IDUse grep to find expected return values and verify hook name
Filter never runsChild theme not active or file not loadedConfirm with wp theme list and check PHP syntax
Layout differs for logged-in usersAdmin bar or role-based contentTest in a private window and disable role-based plugins
Changes hidden by cacheLSCache or plugin cachePurge cache and re-test

Hands-On

  1. Use grep to find 5 generate_* hooks that appear in inc/structure/.
  2. Pick one hook and write a tiny action that prints a static message on a single test page.
  3. Add a CSS rule for your message and verify CLS does not spike.
  4. Find the wrapper class around your main content and write one targeted selector for it (avoid global div selectors).

Quick Reference

NeedUse
Find hook pointsgrep -R "do_action( 'generate_" -n inc/structure templates
Find layout filtersgrep -R "apply_filters( 'generate_" -n inc
Structure code location/wp-content/themes/generatepress/inc/structure/

What's Next