Skip to content

Instantly share code, notes, and snippets.

@justintadlock
Created June 23, 2024 13:43
Show Gist options
  • Save justintadlock/5508740ba42ed7d026d2b4177facc4e2 to your computer and use it in GitHub Desktop.
Save justintadlock/5508740ba42ed7d026d2b4177facc4e2 to your computer and use it in GitHub Desktop.
Reverse stack Columns block style
<?php
// Reverses stack. Reverses the order of the columns on "mobile" using the
// default WordPress breakpoint.
//
// Note: this is not an ideal method of handling this for screen readers. The
// columns are still in their original order in the DOM. But I don't have any
// other solutions at the moment. One alternative for at least one use case is
// to use the Media & Text block, but that case is only for a two-colum image
// and text section.
add_action('init', function() {
register_block_style('core/columns', [
'name' => 'reverse-stack',
'label' => __('Reverse Stack', 'themeslug'),
'inline_style' => '@media (max-width: 782px) {
.wp-block-columns.is-style-reverse-stack {
flex-wrap: wrap-reverse !important;
}
}'
]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment