Using WordPress ‘default_title’ PHP filter

The default_title WordPress PHP filter modifies the default post title initially used in the “Write Post” form.

Usage

add_filter('default_title', 'your_custom_function', 10, 2);

function your_custom_function($post_title, $post) {
  // your custom code here
  return $post_title;
}

Parameters

  • $post_title (string) – The default post title.
  • $post (WP_Post) – The post object.

More information

See WordPress Developer Resources: default_title

Examples

Set a custom default title

Set a custom default title for all new posts.

add_filter('default_title', 'custom_default_title', 10, 2);

function custom_default_title($post_title, $post) {
  $post_title = 'My Custom Default Title';
  return $post_title;
}

Add a date to the default title

Append the current date to the default post title.

add_filter('default_title', 'append_date_to_title', 10, 2);

function append_date_to_title($post_title, $post) {
  $post_title .= ' - ' . date('F j, Y');
  return $post_title;
}

Set default title based on post type

Set a different default title for each post type.

add_filter('default_title', 'set_title_based_on_post_type', 10, 2);

function set_title_based_on_post_type($post_title, $post) {
  if ($post->post_type == 'page') {
    $post_title = 'New Page';
  } elseif ($post->post_type == 'post') {
    $post_title = 'New Blog Post';
  }
  return $post_title;
}

Prefix default title with the author’s name

Add the author’s display name as a prefix to the default post title.

add_filter('default_title', 'prefix_title_with_author_name', 10, 2);

function prefix_title_with_author_name($post_title, $post) {
  $author_name = get_the_author_meta('display_name', $post->post_author);
  $post_title = $author_name . ': ' . $post_title;
  return $post_title;
}

Make the default title uppercase

Transform the default post title to uppercase.

add_filter('default_title', 'uppercase_default_title', 10, 2);

function uppercase_default_title($post_title, $post) {
  $post_title = strtoupper($post_title);
  return $post_title;
}