Вход на сайт

Просмотр новости

Найдите то, что Вас интересует

Pseudo and custom style states in WordPress 7.1

Дата публикации: 05-08-2026 06:49:35

Pseudo states In WordPress 7.1, users have more power over styling the pseudo states of blocks. Currently limited to the Button and Navigation Link blocks, users are able to apply styles to ‘hover’, ‘focus’, ‘focus-visible’ and ‘active’ states. Pseudo states support definitions in theme.json for themers, and block styling in global styles and on block […]

Основное содержимое страницы с новостью.

In WordPress 7.1, users have more power over styling the pseudo states of blocks. Currently limited to the Button and Navigation Link blocks, users are able to apply styles to ‘hover’, ‘focus’, ‘focus-visible’ and ‘active’ states.

Pseudo states support definitions in theme.json JSON, or JavaScript Object Notation, is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML. for themers, and block Block is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. styling in global styles and on block instances for users.

Defining pseudo states for blocks in theme.json

Define pseudo states within the block object using the properties “:hover”, “:focus”, “:focus-visible”, and “:active”. Pseudo state names are always prefixed with a :.

"styles": {
	"blocks": {
		"core/button": {
			"color": {
				"background": "black",
				"text": "white"
			},
			":hover": {
				"color": {
					"background": "blue"
				}
			},
			":focus": {
				"color": {
					"background": "purple"
				}
			}
		}
	}
}

Pseudo states can also be nested within responsive states:

"styles": {
	"blocks": {
		"core/button": {
			"@mobile": {
				":hover": {
					"color": {
						"background": "var:preset|color|contrast",
						"text": "var:preset|color|base"
					}
				}
			}
		}
	}
}
Block instance attributes

The structure for block instance attributes is very similar to the theme.json definition with :hover properties used inside the style attribute:

<!-- wp:button {"backgroundColor":"accent-3","style":{":hover":{"color":{"background":"var:preset|color|accent-2"}}}} -->
<div class="wp-block-button"><a class="wp-block-button__link has-accent-3-background-color has-background wp-element-button">Button with pseudo state background</a></div>
<!-- /wp:button -->
Custom style states

Custom states are an early feature limited to theme.json definition only (no user facing features are exposed) and only the navigation link block. The navigation block uses this to allow styling of the current menu item – that is the menu item whose link matches that of the currently viewed page.

Defining custom states for the navigation link block in theme.json

Styles for the current menu item can be defined using the -current property. Custom states always use the -prefix.

"styles": {
	"blocks": {
		"core/navigation-link": {
			"-current": {
				"color": {
					"text": "var:preset|color|contrast"
				},
				":hover": {
					"color": {
						"text": "var:preset|color|accent-1"
					}
				}
			}
		}
	}
}

As shown above, pseudo states can be nested within custom states. Custom states can also be nested within responsive states.

Style generation

The styles defined for custom states generate css that targets a class name selector. For the navigation link block, that would expand to something like .wp-block-navigation-link .current-menu-item { // styles ... }.

The styles css class name that’s generated in the selector would be declared on supported blocks via a block’s block.json selectors property:

"selectors": {
	"states": {
		"-current": ".wp-block-navigation-link .current-menu-item"
	}
}
Opting out of style state editing

Sites can prevent users from styling block states via the blockStatesEditingEnabled editor setting:

function example_disable_block_states_editing( $settings ) {
	$settings['blockStatesEditingEnabled'] = false;
	return $settings;
}
add_filter( 'block_editor_settings_all', 'example_disable_block_states_editing' );

blockStatesEditingEnabled defaults to true.

When it is false, both the state dropdown in the block inspector’s block card, and the pseudo state options in the “States” dropdown in Global Styles under Styles > Blocks are hidden.

The states affected are the pseudo states, Hover, Focus, Focus-visible and Active, which currently apply to the Button and Navigation Link blocks. In the future this will extend to other states present in the dropdown, like the ability for users to set styles for the Navigation Link’s ‘Current’ state.

This setting does not affect viewport states. Those are controlled separately by responsiveEditingEnabled. Set both to false to remove the state editing interface entirely.

The setting governs the editing interface only. State styles already saved in theme.json, in Global Styles, or in a block’s style attribute are left untouched and are still applied, so existing content renders exactly as before both in the Editor and on the front end.

Reviewed by @ramonopoly, @andrewserong; props @wildworks

#7-1, #dev-notes, #dev-notes-7-1

Схожие новости

#Наименование новостиТональностьИнформативностьДата публикации
1Responsive block styles and configurable viewports in WordPress 7.108.2705-08-2026
2Accessibility Improvements in WordPress 7.109.5913-08-2026
3Filtering registered abilities with wp_get_abilities() in WordPress 7.1011.3305-08-2026
4Iframed Editor Changes in WordPress 7.1010.9903-08-2026
5Hiding the Classic block from the inserter in WordPress 7.10723-06-2026
6A unified public exposure flag for Abilities in WordPress 7.1010.0104-08-2026
7The Classic block stays in the inserter for WordPress 7.10507-07-2026
8WordPress 7.1 Field Guide018.0605-08-2026
9WordPress 7.1 Release Candidate Phase011.7205-08-2026
10WordPress 7.1 Release Candidate 3013.0612-08-2026

Классификация: . Схожих патентов: 0. Схожих новостей: 10. Тональность: 0. Информативность: 7.81. Источник: make.wordpress.org.