Commit 604e288e authored by Gudule Lapointe's avatar Gudule Lapointe
Browse files
parent bd10378f
<?php
/**
* Plugin Name: No "(no title)"
* Plugin URI: PLUGIN SITE HERE
* Plugin Name: No '(no title)'
* Plugin URI: https://magiiic.com/
* Description: Replace '(no title)' in admin lists by an excerpt of the excerpt for posts with empty titles
* Author: Magiiic
* Author URI: https://magiiic.com/
......@@ -12,4 +12,19 @@
* @package No_No_Title
*/
// Your code starts here.
/**
* Modify post titles in the edit.php screen.
* If the post title is empty, then show max 10 words from the post content instead.
* Solution found on https://wordpress.stackexchange.com/questions/189671/show-excerpt-if-no-title-in-admin-view
*/
add_action( 'load-edit.php', function()
{
add_filter( 'the_title', function( $title )
{
$post = get_post();
if( is_a( $post, '\WP_Post' ) && ! $post->post_title && $post->post_content )
$title = wp_trim_words( strip_shortcodes( strip_tags( $post->post_content ) ), 10 );
return $title;
} );
} );
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment