1

My theme and Qtranslate plugin have a conflict and cause many issues on my website's post titles. I cannot trace what causes the issue and I thought that I could handle the title saving myself instead.

I would like to be able to change post title that wordpress uses when saving a post from backend.

How can I do that?

1 Answer 1

5

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;
}
1
  • I just tested your solution and it works!
    – ktsixit
    Oct 8, 2012 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.