Last active
May 26, 2018 04:55
-
-
Save clreed87/df7cfe2f770e3456cb29cb8a5f6d551b to your computer and use it in GitHub Desktop.
Change post title to date if no title is provided
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 | |
// Do not include the opening php tag. | |
//* Change post title to date if no title is provided | |
add_filter( 'wp_insert_post_data', 'crt_update_blank_title' ); | |
function crt_update_blank_title( $data ) { | |
$title = $data['post_title']; | |
$post_type = $data['post_type']; | |
if ( empty( $title ) && ( $post_type == 'post' ) ) { | |
$timezone = get_option('timezone_string'); | |
date_default_timezone_set( $timezone ); | |
$title = date( 'Y-m-d H.i.s' ); | |
$data['post_title'] = $title; | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment