Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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;
}
share|improve this answer
    
I just tested your solution and it works! –  ktsixit Oct 8 '12 at 13:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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