admin管理员组

文章数量:1122832

How to remove View post from this message ?

My code is like below.

public function game_updated_messages( $messages )

    {
    
    $messages['game'] = $messages['post'];
    
    $messages['game'][1] = 'Post updated.';
    
    $messages['game'][6] = 'Post published.';
    
    return $messages;
    
    }

How to remove View post from this message ?

My code is like below.

public function game_updated_messages( $messages )

    {
    
    $messages['game'] = $messages['post'];
    
    $messages['game'][1] = 'Post updated.';
    
    $messages['game'][6] = 'Post published.';
    
    return $messages;
    
    }

Share Improve this question asked Jul 16, 2024 at 14:44 FoysalFoysal 4451 gold badge5 silver badges15 bronze badges 3
  • 1 wherehow is game_updated_messages called? Is it on a filter if so which ones? I'm assuming this is in the classic editor? It's difficult to tell from the screenshot if it's the classic editor, a quick edit action, or something else. Is game a CPT? If so what are the labels in its registration? – Tom J Nowell Commented Jul 16, 2024 at 15:06
  • Thanks @TomJNowell. I called it like this add_filter( 'post_updated_messages', [ $this, 'game_updated_messages' ] );. Yes, game is a CPT. How to find the labels in its registration ? Thanks. – Foysal Commented Jul 17, 2024 at 4:34
  • 1 can you edit your question to include that information? Labels are provided when you register the post type, look at the code that registers that post type and it'll be obvious, labels usually make up to half the code when registering a post type – Tom J Nowell Commented Jul 17, 2024 at 8:22
Add a comment  | 

1 Answer 1

Reset to default 3

I think the issue is this piece of code $messages['game'] = $messages['post'];. $messages will contains all the updated messages for all custom post type. In this case, your CPT is game, so you should change the array item of game only.

The correct code should be

public function game_updated_messages( $messages )
{
    $messages['game'][1] = 'Post updated.';
    $messages['game'][6] = 'Post published.';
    
    return $messages;
}

You can try to dump the variable $messages and see all the result it returns.

本文标签: plugin developmentRemove View post Text