Skip to content

Admin Controller

The Admin_Controller class lets you customize the WordPress admin editor on a per-template or per-post-type basis. You can hide unwanted metaboxes (excerpt, editor, comments, etc.) and set up post-save redirects — all from a simple configuration array.


  • Hide metaboxes: Remove unwanted UI elements from the editor screen
  • Post-save redirects: Redirect to a custom URL after saving a post (static or dynamic)
  • Multiple match types: Apply rules by template name, post type, post ID, or custom condition
  • Dual removal strategy: Uses both remove_meta_box() and CSS injection for reliability
  • Gutenberg compatible: Removes editor support early enough for Gutenberg to respect it

  • identifier (string): The value to match against — template filename, post type slug, or post ID.
  • match_type (string): How to match: 'template', 'post_type', 'post_id', or 'condition'.
  • hide_elements (array): Elements to hide from the admin screen.
  • redirect (string|callable): URL or callback for redirect after save.
  • condition (callable): Optional custom condition that must return true for rules to apply.
ValueWhat it hides
excerptExcerpt metabox
thumbnail / featured_imageFeatured image metabox
editorThe WordPress editor (classic or Gutenberg)
custom_fieldsCustom fields metabox
commentsComments metabox
slugSlug/permalink editor
authorAuthor metabox
revisionsRevisions metabox
page_attributesPage attributes (template, order)
trackbacksTrackbacks metabox
categoriesCategories metabox
tagsTags metabox

When using only ACF Flexible Content on a page, hide the default WordPress editor:

<?php
// In functions/project/config/admin-controller_config.php
return [
[
'identifier' => 'page-modules.php',
'match_type' => 'template',
'hide_elements' => ['editor'],
],
];

After saving a post of a specific type, redirect the user back to the post list:

<?php
[
'identifier' => 'testimonial',
'match_type' => 'post_type',
'redirect' => 'edit.php?post_type=testimonial',
],

Redirect to different locations based on post data:

<?php
[
'identifier' => 'resource',
'match_type' => 'post_type',
'redirect' => function ($post_id, $post) {
$type = get_the_terms($post_id, 'resource_type');
if ($type && $type[0]->slug === 'case-study') {
return 'edit.php?post_type=resource&resource_type=case-study';
}
return 'edit.php?post_type=resource';
},
],

Apply rules only when a custom condition is met:

<?php
[
'identifier' => 'post',
'match_type' => 'post_type',
'condition' => function ($post_id, $post) {
return get_post_meta($post_id, 'use_minimal_editor', true) === '1';
},
'hide_elements' => ['excerpt', 'comments', 'author'],
],

<?php
[
'identifier' => 'page-landing.php',
'match_type' => 'template',
'hide_elements' => ['editor', 'excerpt', 'comments'],
'redirect' => 'edit.php?post_type=page',
],

  • identifier (string): Template name (e.g., 'page-modules.php'), post type slug (e.g., 'resource'), or post ID (e.g., '42').
  • match_type (string): Determines how identifier is matched:
    • template: Matches the _wp_page_template post meta
    • post_type: Matches the post’s type
    • post_id: Matches a specific post ID
    • condition: Uses only the condition callback (ignores identifier)
  • hide_elements (array): List of element strings to hide.
  • redirect (string|callable): Static URL string or function($post_id, $post) returning a URL.
  • condition (callable): A function receiving ($post_id, $post) that must return true. Can be combined with other match types for additional filtering.

Knowledge Check

Test your understanding of this section

Loading questions...