Global Layout Framework
warning
Template overrides are a last resort. Prefer hooks/filters first to keep future GeneratePress updates painless.
Global Layout Framework Explained
| Layer | What it controls | Primary locations |
|---|---|---|
| Structure functions | Builds header/footer/sidebar/container markup | /wp-content/themes/generatepress/inc/structure/ |
| Templates | WordPress template hierarchy entry points | /wp-content/themes/generatepress/templates/ |
| Layout settings | Container width, sidebars, padding, alignment | Customizer + defaults + filters |
| Hook points | Injection points around structural regions | do_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
Step 2: Find Layout-Related Filters
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 practice | Why |
|---|---|
| Use filters for layout decisions | Layout should be deterministic and easy to audit |
| Use actions for markup injections | Keeps structure changes localized |
| Keep CSS changes close to the component | Avoid global overrides that regress other pages |
| Measure impact (CLS/INP/LCP) | Layout tweaks often have performance side effects |
Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
| Sidebar still shows | Filter returns wrong layout ID | Use grep to find expected return values and verify hook name |
| Filter never runs | Child theme not active or file not loaded | Confirm with wp theme list and check PHP syntax |
| Layout differs for logged-in users | Admin bar or role-based content | Test in a private window and disable role-based plugins |
| Changes hidden by cache | LSCache or plugin cache | Purge cache and re-test |
Hands-On
- Use
grepto find 5generate_*hooks that appear ininc/structure/. - Pick one hook and write a tiny action that prints a static message on a single test page.
- Add a CSS rule for your message and verify CLS does not spike.
- Find the wrapper class around your main content and write one targeted selector for it (avoid global
divselectors).
Quick Reference
| Need | Use |
|---|---|
| Find hook points | grep -R "do_action( 'generate_" -n inc/structure templates |
| Find layout filters | grep -R "apply_filters( 'generate_" -n inc |
| Structure code location | /wp-content/themes/generatepress/inc/structure/ |
What's Next
- Next: Hooks Overview
- Related: Customizer-Based Design System