Created
February 28, 2017 15:33
-
-
Save octalmage/e0eb75ae9c1336b4a2bea9f6690337d7 to your computer and use it in GitHub Desktop.
Modify the edit.php screen to show post excerpts if there is no title.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: If No Title | |
Description: Modify the edit.php screen to show post excerpts if there is no title. | |
Version: 0.0.1 | |
*/ | |
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; | |
} ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment