Change post title during post saving process

You can hook into wp_insert_post_data and change things.

<?php
add_filter('wp_insert_post_data', 'wpse67262_change_title');
function wpse67262_change_title($data)
{
    $data['post_title'] = 'This will change the title';
    return $data;
}

Obviously you’re going to have to some checks and stuff so you don’t change every post title. That hook will also fire every time the post is saved (adding a new post, updating, trashing a post, etc) and for every post type. $data is an associative array with every column you’d find in the {$wpdb->prefix}_posts table as keys. So if you just wanted to changed posts:

<?php
add_filter('wp_insert_post_data', 'wpse67262_change_title');
function wpse67262_change_title($data)
{
    if('post' != $data['post_type'])
        return $data;

    $data['post_title'] = 'This will change the title';

    return $data;
}

Leave a Comment