Setting the file. One moment.
Subchapter 10.1
references/anti-patterns.mdMarkdown6 KBView on GitHub
Common mistakes that produce generic, broken, or inaccessible patterns.
<!-- WRONG: inline <style> tag -->
<style>.my-custom-hero { background: linear-gradient(...); }</style>
<!-- WRONG: custom CSS class not from blocks -->
<div class="my-custom-card">
<!-- CORRECT: use block attributes -->
<!-- wp:group {"style":{"color":{"gradient":"linear-gradient(...)"}}} -->// WRONG: hardcoded hex when a preset exists
{"style":{"color":{"background":"#000000","text":"#ffffff"}}}
// CORRECT: use theme presets for theme compatibility
{"backgroundColor":"contrast","textColor":"base"}Use hardcoded values only when no suitable preset exists and the design requires a specific color.
// WRONG: raw text, not translatable, not escaped
<h2>Our Services</h2>
// WRONG: translatable but not escaped
<h2><?php _e( 'Our Services', 'theme-slug' ); ?></h2>
// CORRECT: escaped and translatable
<h2><?php esc_html_e( 'Our Services', 'theme-slug' ); ?></h2>// WRONG: runs at registration time, not render time
<?php $recent = get_posts( array( 'numberposts' => 3 ) ); ?>
// CORRECT: use Query Loop block for dynamic content
<!-- wp:query {"query":{"perPage":3,"postType":"post"}} --><!-- WRONG: missing closing comment -->
<!-- wp:group -->
<div class="wp-block-group">
<!-- wp:heading -->
<h2>Title</h2>
<!-- /wp:heading -->
<!-- Missing: /wp:group -->
<!-- WRONG: mismatched nesting -->
<!-- wp:group -->
<!-- wp:columns -->
<!-- /wp:group -->
<!-- /wp:columns --><!-- WRONG: external placeholder service -->
<img src="https://via.placeholder.com/800x400" alt=""/>
<!-- CORRECT: use theme assets or descriptive placeholder -->
<img src="<?php echo esc_url( get_theme_file_uri( 'assets/images/placeholder.webp' ) ); ?>"
alt="<?php esc_attr_e( 'Featured image', 'theme-slug' ); ?>"/><!-- WRONG -->
<!-- wp:image -->
<figure class="wp-block-image"><img src="photo.jpg" alt=""/></figure>
<!-- /wp:image -->
<!-- CORRECT: descriptive alt for informational images -->
<!-- wp:image {"alt":"Team members collaborating around a whiteboard"} -->Decorative images (backgrounds, dividers) can use empty alt, but informational images must describe content.
<!-- WRONG: jumps from h2 to h5 -->
<!-- wp:heading {"level":2} --> Section Title
<!-- wp:heading {"level":5} --> Subsection
<!-- CORRECT: sequential levels -->
<!-- wp:heading {"level":2} --> Section Title
<!-- wp:heading {"level":3} --> SubsectionPatterns should use h2 as the top level (h1 is the page title). Descend sequentially: h2 → h3 → h4.
When using dark backgrounds, verify text presets provide adequate contrast:
{"backgroundColor":"contrast","textColor":"base"} — typically safe (dark bg, light text)<!-- WRONG -->
<a class="wp-block-button__link">Click Here</a>
<a class="wp-block-button__link">Read More</a>
<!-- CORRECT: describes the action or destination -->
<a class="wp-block-button__link"><?php esc_html_e( 'View Our Services', 'theme-slug' ); ?></a>
<a class="wp-block-button__link"><?php esc_html_e( 'Download the Report', 'theme-slug' ); ?></a>Spacer blocks should include aria-hidden="true" (WordPress adds this automatically). If generating custom separator patterns, ensure decorative elements don’t announce to screen readers.
<!-- wp:block --> has matching <!-- /wp:block -->esc_html_e() or esc_html__()esc_url()esc_attr_e() or esc_attr__()Slug in header uses correct namespace: theme-slug/pattern-name<style>, no <script>, no custom CSS classesSlug unless intentionally creating a new pattern