WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a custom wordpress title for a posts made under a custom post. Basically, its a version changelog for an application. I would like to only input the version number in the title field, and the output has to be standardized with a string accordingly.

My custom post type is 'custom_version' and the title output that I'm looking for is "Application has been updated to version ".

I've understood that this can be achieved using add_filter and I've tried playing with this code for days now, but I'm not really a PHP Pro so help is much appreciated :) Here's the code:

add_filter('the_title', 'new_title');
function new_title($title) {
    global $post, $post_ID;
    $title['custom_version'] = 'Application has been updated to v'.$title;
    return $title;
share|improve this question
up vote 4 down vote accepted

The issue is that you are mixing up the $title variables. $title is the parameter passed to the new_title function, but then you use it as an array: $title['custom_version']. Try this:

add_filter('the_title', 'new_title', 10, 2);
function new_title($title, $id) {
    if('custom_version' == get_post_type($id))
        $title = 'Application has been updated to v'.$title;
    return $title;

I'd also highly recommend prefixing your function with a unique prefix because you may run into another plugin/theme using a function called new_title, which will reek havoc!

share|improve this answer
Thanks for the response tollmanz, I tried your code, but the problem is, it replaces ALL titles including that of pages..Here is a reference of where its being done: titaniumtrack.com/changelog/titanium-backup/3-0-6 – shahz Aug 22 '11 at 4:46
I am actually trying to add this filter only to custom post types with identified "custom_version".. – shahz Aug 22 '11 at 4:55
Edited...I check that the post_ID is associated with a post of post type "custom_version" before manipulating the title. Sorry about the initial version. I didn't realize that it needed to be for only the one CPT. – tollmanz Aug 22 '11 at 4:57

Your Answer


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.