Skip to content

Instantly share code, notes, and snippets.

@clreed87
Last active May 26, 2018 04:55
Show Gist options
  • Save clreed87/df7cfe2f770e3456cb29cb8a5f6d551b to your computer and use it in GitHub Desktop.
Save clreed87/df7cfe2f770e3456cb29cb8a5f6d551b to your computer and use it in GitHub Desktop.
Change post title to date if no title is provided
<?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