The question:
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?
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
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' );
Method 2
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0