Skip to main content

Accessibility & Semantics

warning

Accessibility regressions often come from small markup changes. Test with keyboard-only navigation and verify heading structure after updates.

Accessibility & Semantics Explained

AreaWhat it meansExample
SemanticsUse correct HTML elements<nav>, <main>, <header>
Keyboard supportEverything usable without a mousefocus states, tab order
Skip linksJump to main content<a href="#main">Skip</a>
ContrastText is readableWCAG contrast checks

Why It Matters

  • Accessibility improves UX for everyone.
  • It reduces legal/compliance risk.
  • It also helps SEO and overall quality.

How It Works

GeneratePress already includes accessibility work. Your child theme should extend it carefully: add small enhancements via hooks and CSS.

Practical Walkthrough

Step 1: Locate GeneratePress Accessibility CSS

locate-accessibility-css.sh
cd /var/www/html/wp-content/themes/generatepress
ls -lah assets/css | grep accessibility || true
wp-content/themes/generatepress-child/inc/hooks.php
<?php

add_action( 'wp_body_open', function() {
echo '<a class="skip-link" href="#main">Skip to content</a>';
} );

Step 3: Add Focus Styles

wp-content/themes/generatepress-child/assets/css/a11y.css
.skip-link {
position: absolute;
left: -9999px;
}

.skip-link:focus {
left: 16px;
top: 16px;
background: #ffffff;
color: #0f172a;
padding: 8px 12px;
border: 2px solid #0f172a;
}

a:focus-visible, button:focus-visible {
outline: 2px solid #1e3a8a;
outline-offset: 2px;
}

Step 4: Verify the Target Anchor Exists

Your skip link targets #main. Confirm your theme outputs a main region or an element with that ID.

search-for-main-anchor.sh
cd /var/www/html/wp-content/themes/generatepress
grep -R "id=\"main\"\|<main" -n templates inc/structure 2>/dev/null | head -n 60 || true

Practical Examples

Example 1: Heading Order Rule

Use one H1 per page. In hero sections, ensure the page title does not create a second H1.

Example 2: Icon Buttons Need Text

If you add icon-only buttons, include screen-reader text or aria-label.

Example 3: A Quick Accessibility Checklist

CheckTool
Keyboard navTab/Shift+Tab
ContrastLighthouse / WCAG checker
HeadingsInspect DOM
Focus stylesVisual test
Icon link pattern
<a href="https://example.com" aria-label="Follow us on Example">
<span aria-hidden="true"></span>
</a>

Best Practices

PracticeWhy
Test with keyboard onlyFinds most issues quickly
Keep focus visibleUsers need navigation context
Use semantic HTMLBetter assistive tech support
Avoid text-in-imagesAccessibility and SEO
Keep interactive targets largeBetter mobile usability
Use ARIA sparinglyPrefer native semantics first

Troubleshooting

SymptomCauseFix
Skip link not visibleCSS missingAdd .skip-link:focus styles
Focus outline removedCSS resetRestore focus-visible outlines
Contrast failsOff-brand colorsAdjust tokens and re-test

Hands-On

  1. Add a skip link via wp_body_open.
  2. Add focus styles in a11y.css.
  3. Test tab order on mobile and desktop.
  4. Run Lighthouse on one page and note any a11y warnings.

Quick Reference

TaskFile
Skip link hookinc/hooks.php
Focus stylesassets/css/a11y.css

What's Next