Yes, you can modify the WordPress admin posts screen to display a brief excerpt instead of titles for posts that don’t have titles. This can make navigation and management much easier, especially for your workflow where posts rarely have titles.
You can achieve this by adding some custom code to your theme’s functions.php
file or by creating a custom plugin. Here’s how you can do it:
// Replace post titles with excerpts on admin posts screen
function custom_admin_post_list_titles($title, $post_id) {
// Check if the post doesn't have a title
if (empty(get_the_title($post_id))) {
// Get the post content and truncate it to create a brief excerpt
$content = get_post_field('post_content', $post_id);
$excerpt = wp_trim_words($content, 20, '...'); // Adjust the word count as needed
// Output the excerpt instead of the title
return $excerpt;
}
// If the post has a title, return the original title
return $title;
}
add_filter('the_title', 'custom_admin_post_list_titles', 10, 2);
This code snippet hooks into the the_title
filter, which filters the post title displayed in various contexts, including the admin posts screen. It checks if the post doesn’t have a title (i.e., the title is empty), and if so, it retrieves the post content and truncates it to create a brief excerpt. Finally, it returns the excerpt instead of the title.
You can adjust the word count in the wp_trim_words
function according to your preference for how long you want the excerpt to be.
Add this code to your theme’s functions.php
file or create a custom plugin for it. Once added, the WordPress admin posts screen will display excerpts for posts that don’t have titles, making it easier for you to navigate and manage your posts.