Classic theme sidebars widgets

From Lonsdale201/wp-agent-skills · View interactive version

Classic theme sidebars widgets is an AI agent skill from the GitHub repository Lonsdale201/wp-agent-skills. Build or audit classic theme widget areas and sidebars for WP 7.1. Covers `widgets_init`, `register_sidebar()`, stable sidebar IDs, `before_widget` and `before_title` wrappers, `dynamic_sidebar()`, `is_active_sidebar()`, `get_sidebar()`, `sidebar-{name}.php`, `show_in_rest`, semantic aside/footer/he

How to use this skill

Skill file

Classic Theme Sidebars and Widgets

Use this when adding or reviewing widget areas in a classic PHP theme: blog sidebars, footer columns, header widget areas, shop sidebars, or template-specific widget regions.

In WordPress naming, "sidebar" means a registered widget area. It does not have to appear visually at the side of the layout.

When to Use This Skill

Register Widget Areas

Register widget areas on widgets_init.

add_action( 'widgets_init', 'mytheme_register_sidebars' );

function mytheme_register_sidebars() {
	register_sidebar(
		array(
			'name'          => __( 'Primary sidebar', 'textdomain' ),
			'id'            => 'sidebar-1',
			'description'   => __( 'Widgets shown beside the main content.', 'textdomain' ),
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
			'show_in_rest'  => false,
		)
	);
}

Rules:

Multiple Areas

Use predictable IDs for repeated footer columns.

for ( $i = 1; $i <= 4; $i++ ) {
	register_sidebar(
		array(
			'name'          => sprintf(
				/* translators: %d: Footer column number. */
				__( 'Footer column %d', 'textdomain' ),
				$i
			),
			'id'            => 'footer-' . $i,
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);
}

Rules:

Render a Sidebar

Use is_active_sidebar() before outputting layout wrappers.

if ( is_active_sidebar( 'sidebar-1' ) ) :
	?>
	<aside id="secondary" class="widget-area" aria-label="<?php esc_attr_e( 'Sidebar', 'textdomain' ); ?>">
		<?php dynamic_sidebar( 'sidebar-1' ); ?>
	</aside>
	<?php
endif;

Rules:

Sidebar Template Files

Use get_sidebar() to load sidebar template files.

get_sidebar();          // sidebar.php
get_sidebar( 'footer' ); // sidebar-footer.php

Rules:

REST and Block Widget Era

register_sidebar() supports show_in_rest.

Rules:

Markup and Accessibility

Good widget-area output:

Wrapper choice examples:

| Area | Wrapper |

|---|---|

| Blog sidebar | <aside class="widget-area"> |

| Footer column | <section class="footer-widget-area"> |

| Header utility area | <div class="header-widget-area"> or labeled <aside> |

Theme vs Plugin Boundary

Themes may register display regions. Plugins should register reusable widgets that provide business functionality.

Good theme-owned widget areas:

Bad theme-owned functionality:

Review Checklist

Common Mistakes

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.