Skip to content

Instantly share code, notes, and snippets.

@juanmaguitar
Last active January 4, 2026 07:28
Show Gist options
  • Select an option

  • Save juanmaguitar/2aa2d3ec59024827088c1853ed238e7b to your computer and use it in GitHub Desktop.

Select an option

Save juanmaguitar/2aa2d3ec59024827088c1853ed238e7b to your computer and use it in GitHub Desktop.
// ============================================
// DETECTING SIDEBAR STATE
// ============================================
// Get currently active sidebar
wp.data.select('core/interface').getActiveComplementaryArea('core')
// Returns: 'edit-post/document', 'edit-post/block', null, etc.
// Check if document sidebar is open
wp.data.select('core/interface').getActiveComplementaryArea('core') === 'edit-post/document'
// Check if block inspector is open
wp.data.select('core/interface').getActiveComplementaryArea('core') === 'edit-post/block'
// Check if any sidebar is open
!!wp.data.select('core/interface').getActiveComplementaryArea('core')
// Check if specific panel is open
wp.data.select('core/edit-post').isEditorPanelOpened('taxonomy-panel-category')
// Check panels available
wp.data.select('core/edit-post').getPreferences()
// ============================================
// OPENING SIDEBARS
// ============================================
// Open document sidebar (post settings)
wp.data.dispatch('core/interface').enableComplementaryArea('core', 'edit-post/document')
// Open block inspector
wp.data.dispatch('core/interface').enableComplementaryArea('core', 'edit-post/block')
// Alternative: Using edit-post wrapper
wp.data.dispatch('core/edit-post').openGeneralSidebar('edit-post/document')
wp.data.dispatch('core/edit-post').openGeneralSidebar('edit-post/block')
// ============================================
// CLOSING SIDEBARS
// ============================================
// Close any open sidebar
wp.data.dispatch('core/interface').disableComplementaryArea('core')
// Alternative: Using edit-post wrapper
wp.data.dispatch('core/edit-post').closeGeneralSidebar()
// ============================================
// TOGGLE SIDEBARS
// ============================================
// Toggle document sidebar
const current = wp.data.select('core/interface').getActiveComplementaryArea('core');
if (current === 'edit-post/document') {
wp.data.dispatch('core/interface').disableComplementaryArea('core');
} else {
wp.data.dispatch('core/interface').enableComplementaryArea('core', 'edit-post/document');
}
// Smart toggle (like Ctrl+Shift+,)
const activeSidebar = wp.data.select('core/interface').getActiveComplementaryArea('core');
const hasBlockSelection = !!wp.data.select('core/block-editor').getBlockSelectionStart();
const isAnySidebarOpen = ['edit-post/document', 'edit-post/block'].includes(activeSidebar);
if (isAnySidebarOpen) {
wp.data.dispatch('core/interface').disableComplementaryArea('core');
} else {
const sidebarToOpen = hasBlockSelection ? 'edit-post/block' : 'edit-post/document';
wp.data.dispatch('core/interface').enableComplementaryArea('core', sidebarToOpen);
}
// ============================================
// CONTROLLING PANELS WITHIN SIDEBARS
// ============================================
// Toggle a panel (post-status, featured-image, etc.)
wp.data.dispatch('core/edit-post').toggleEditorPanelOpened('taxonomy-panel-category')
// Open sidebar and ensure panel is expanded
wp.data.dispatch('core/edit-post').openGeneralSidebar('edit-post/document');
if (!wp.data.select('core/edit-post').isEditorPanelOpened('taxonomy-panel-category')) {
wp.data.dispatch('core/edit-post').toggleEditorPanelOpened('taxonomy-panel-category');
}
// Get panels available
// Common panel names: 'post-status', 'taxonomy-panel-category'
wp.data.select('core/edit-post').getPreferences()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment