Your functions.php
file is more than just a catch-all—it’s a powerful way to fine-tune your theme’s behavior and the block editor experience without reaching for a plugin.
Here are some of my go-to snippets for theme-level control, helping you clean up the editor, register key features, and limit unwanted bloat.
🎨 1. Register Custom Navigation Menus
add_action('after_setup_theme', function() {
register_nav_menus([
'primary' => 'Primary Menu',
'footer' => 'Footer Menu'
]);
});
Why use it: Allows you to assign menus in the Customizer or Site Editor. Needed for classic themes and some hybrid block builds.
🚫 2. Limit Available Block Types
add_filter('allowed_block_types_all', function($allowed_blocks, $editor_context) {
return [
'core/paragraph',
'core/heading',
'core/image',
'core/columns',
'core/buttons',
'core/group'
];
}, 10, 2);
Why use it: Prevents clients from using blocks you don’t want in the layout—like Cover, Quote, or Pullquote. Keeps things focused.
✏️ 3. Add Custom Block Styles (e.g. Rounded Images)
register_block_style(
'core/image',
[
'name' => 'rounded',
'label' => 'Rounded Image',
'inline_style' => 'img { border-radius: 1rem; }'
]
);
Why use it: Let users apply custom visual styles to blocks (like rounded corners) without needing a class or plugin.
🧱 4. Disable Core Patterns (if you’re building your own)
remove_action('init', 'register_core_block_patterns');
remove_action('init', 'register_core_block_pattern_categories');
Why use it: Stops the editor from loading dozens of default patterns you don’t use. Makes your own patterns stand out.
🖌️ 5. Limit Editor Colors via theme.json
"settings": {
"color": {
"palette": [
{ "name": "Dark", "slug": "dark", "color": "#111" },
{ "name": "Accent", "slug": "accent", "color": "#f97316" }
]
}
}
Why use it: Keeps your color usage consistent across blocks. Clients won’t go rogue with neon pink.
🧪 6. Add Custom Template Parts (for block themes)
add_action('init', function () {
register_block_template_part(
get_theme_file_path('parts/hero.html'),
'theme',
'header/hero',
[
'title' => 'Hero Section',
'area' => 'uncategorized'
]
);
});
Why use it: Allows reusing template parts across block templates (header.html
, home.html
, etc.).
🧠 7. Add Global Editor Notice (Visual Alert for Clients)
add_action('enqueue_block_editor_assets', function () {
echo '<style>.edit-post-header:after {
content: "⚠️ Remember to save template changes!";
color: #d6336c;
font-weight: bold;
margin-left: 2rem;
}</style>';
});
Why use it: Great for reminding clients to click “Save” in FSE. Adds visual cues inside the editor header.
🔒 8. Lock Specific Blocks or Regions (Block Locking)
add_filter('block_editor_settings_all', function ($settings) {
$settings['canLockBlocks'] = true;
return $settings;
});
Why use it: Enables the UI for block locking (prevent moving/removing critical layout blocks). Works well with patterns and FSE templates.
🧼 9. Remove Unused Block Styles (Like Button Variants)
add_action('init', function () {
wp_deregister_style('wp-block-button');
});
Why use it: Cleans up default button styles you might be replacing with your own SCSS. Helps reduce CSS bloat.
🧭 Final Thoughts
These are the kind of customizations I build into nearly every child theme or plugin-powered layout. They keep the editing experience tight, intuitive, and aligned with the actual front-end.
They also prevent surprises—especially when handing off a site to clients or managing content at scale.
Leave a Reply