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.

I'm trying to include the post title in a custom post type edit screen. For example if the post is called Biography, I want the edit page title to be 'Edit Biography'. I'm using the below code:

function my_post_register() {
 $mypagetitle = $post->post_title;
 $labels = array(
  'edit_item' => __('Edit '.$mypagetitle),

Why isn't this displaying the post title?

share|improve this question
    
When are you calling this function? I can assume there is a timing issue here - shouldn't you already have registered your post type before you query for the post? –  Jan Fabry Oct 1 '10 at 7:41
    
Yeah I'm calling this before registering the post type. So I guess I need a way of changing the labels after the post type has been created? –  fxfuture Oct 1 '10 at 7:49
    
I would guess so. Look at the place in the PHP page that displays the title, and work backwards from there, to find the best place to edit the title and other labels, using a filter for example. –  Jan Fabry Oct 1 '10 at 8:11
    
I've found out it's this bit of code in post.php: $title = $post_type_object->labels->edit_item; but I've got no idea how to filter it! –  fxfuture Oct 1 '10 at 19:46
    
I don't remember exactly how it was at the time of asking, but this is definitely default behavior now. –  Johannes Pille Oct 31 '13 at 17:04

2 Answers 2

up vote 1 down vote accepted

This will do it:

function edit_screen_title() {
    global $post, $title, $action, $current_screen;

    if( isset( $current_screen->post_type ) && $current_screen->post_type == 'post' && $action == 'edit' )
        $title = 'Edit ' . $post->post_title;
}

add_action( 'admin_head', 'edit_screen_title' );
share|improve this answer
    
thanks again - you have been so helpful! –  fxfuture Oct 4 '10 at 1:01
    
you are welcome –  sorich87 Oct 4 '10 at 1:31

two things I'd suggest. First try adding global $post as the first line in your function

global $post;

Also in places I've had trouble getting the post_title, then I found another function

$mypagetitle = single_post_title('', false);

You could try that - more details: http://codex.wordpress.org/Function_Reference/single_post_title

share|improve this answer
    
Thanks - I tried that but I think it's more of a timing issue as Jan suggests above –  fxfuture Oct 1 '10 at 19:49

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.