• I am using WP (currently v6.5.3) for posting via jsonfeed to?my micro.blog and then cross-posting to Mastodon/Bluesky (and occasionally manually posting the items to X or Threads).

    As such, my posts rarely have titles, which makes it very hard to navigate the WP “posts” admin screen. Is there any way to show a brief excerpt instead?

    • This topic was modified 6 months, 3 weeks ago by Yui.
    • This topic was modified 6 months, 3 weeks ago by James Huff. Reason: link moved to proper field

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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.

    Thread Starter defjaf

    (@defjaf)

    Thanks!

    In fact I had to change

        (empty(get_the_title($post_id)))

    to

    ( empty($title) )

    Any idea why?

    (And now I have to learn how to make this into a plugin…)

    Moderator bcworkz

    (@bcworkz)

    The reason you had to change the offered code is because get_the_title() applies “the_title” filter, which your callback had already hooked into. By calling get_the_title() in the callback, it causes an infinite loop situation due to recursive code. Anyway, directly using $title is more efficient since it’s already passed to your callback. No need to go fetch it again through other means.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress as microblog: show excerpt instead of “(no title)” in posts view’ is closed to new replies.