Managing pages that use different custom templates can be difficult when a website has many pages.
This snippet applies different background colors to rows in WordPress Admin → Pages → All Pages, based on each page’s assigned template. It helps developers visually distinguish selected templates without opening individual pages.
How to use
- Add the code to your child theme’s
functions.phpfile or a PHP snippets plugin. - Replace the three example template paths in
$template_classeswith the exact filenames assigned to your pages. - Open WordPress Admin → Pages → All Pages.
- Each row will receive the background color associated with its template.
Color legend
- Amber: Default template
- Blue: Landing page template
- Green: Contact page template
- Lavender: Full-width template
- Light gray: Other custom templates
Important notes
- The example filenames are placeholders. Update them to match your actual template paths, including subdirectories.
- The snippet changes admin presentation only; it does not modify page content or template assignments.
- It uses WordPress’s
get_page_template_slug()to determine the assigned template. - Test on a staging website before deploying to production.
/**
* Add template-specific CSS classes to Pages admin rows.
*/
add_filter(
'post_class',
'alkesh_add_page_template_admin_row_class',
10,
3
);
function alkesh_add_page_template_admin_row_class(
$classes,
$class,
$post_id
) {
if ( ! is_admin() || ! function_exists( 'get_current_screen' ) ) {
return $classes;
}
$screen = get_current_screen();
if (
! $screen ||
'edit' !== $screen->base ||
'page' !== $screen->post_type ||
'page' !== get_post_type( $post_id )
) {
return $classes;
}
$template = get_page_template_slug( $post_id );
// Identify pages using the default template.
if ( empty( $template ) ) {
$classes[] = 'alkesh-template-default';
return $classes;
}
/*
* Map exact template filenames to CSS class names.
* Replace these examples with your actual template filenames.
*/
$template_classes = array(
'templates/landing-page.php' => 'alkesh-template-landing',
'templates/contact.php' => 'alkesh-template-contact',
'templates/full-width.php' => 'alkesh-template-full-width',
);
if ( isset( $template_classes[ $template ] ) ) {
$classes[] = $template_classes[ $template ];
} else {
$classes[] = 'alkesh-template-other';
}
return $classes;
}
/**
* Apply template-specific colors in the Pages admin list.
*/
add_action(
'admin_head-edit.php',
'alkesh_style_page_template_admin_rows'
);
function alkesh_style_page_template_admin_rows() {
$screen = get_current_screen();
if (
! $screen ||
'edit' !== $screen->base ||
'page' !== $screen->post_type
) {
return;
}
?>
<style>
/* Default page template: amber */
.wp-list-table tr.alkesh-template-default > th,
.wp-list-table tr.alkesh-template-default > td {
background-color: #fff3cd;
}
/* Landing page template: blue */
.wp-list-table tr.alkesh-template-landing > th,
.wp-list-table tr.alkesh-template-landing > td {
background-color: #dceeff;
}
/* Contact page template: green */
.wp-list-table tr.alkesh-template-contact > th,
.wp-list-table tr.alkesh-template-contact > td {
background-color: #dff3e4;
}
/* Full-width template: lavender */
.wp-list-table tr.alkesh-template-full-width > th,
.wp-list-table tr.alkesh-template-full-width > td {
background-color: #eee5ff;
}
/* Other custom templates: light gray */
.wp-list-table tr.alkesh-template-other > th,
.wp-list-table tr.alkesh-template-other > td {
background-color: #f0f0f1;
}
</style>
<?php
}
Tested on
WordPress 7.1.3
WordPress Admin
Reported by the author on October 28, 2026. WPFolks has not verified this.
