web-dev-qa-db-ja.com

投稿編集ページに投稿タイトルを表示しますか?

カスタム投稿タイプ編集画面に投稿タイトルを含めようとしています。たとえば、投稿が「経歴」という場合、編集ページのタイトルを「経歴の編集」にします。私は以下のコードを使っています:

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

これで投稿のタイトルが表示されないのはなぜですか。

2
fxfuture

これはそれを行います:

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' );
3
sorich87

私が提案する2つのこと最初に、関数の最初の行としてglobal $ postを追加してみてください。

global $post;

また、post_titleの取得に問題がある場所では、別の関数を見つけました。

$mypagetitle = single_post_title('', false);

あなたはそれを試すことができます - 詳細: http://codex.wordpress.org/Function_Reference/single_post_title

0
keranm