2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WordPressで「プレビュー」、「ゴミ箱へ移動」ボタンの非表示化

Last updated at Posted at 2020-12-08

ワードプレスのテーマtwentytwentyoneを基盤に、管理者画面の投稿編集画面に表示されるプレビューボタンとゴミ箱へ移動を非表示にする実装を行ったので、備忘録的にこの記事を残す。

環境情報

PHP:version 7.3.12
WordPress:version 5.5.3
WPテーマ:twentytwentyone

作業

function.php
//「プレビュー」と「ゴミ箱へ移動」ボタンを非表示
add_action('admin_print_styles', 'admin_preview_delete_css_custom');
function admin_preview_css_custom() {
    $current_screen = get_current_screen();
    if(isset($current_screen) && (
    $current_screen->post_type === 'company' ||
    $current_screen->post_type === 'office'
    ) ) {
        $style = '<style>#preview-action {display: none;}</style>';
        $style .= '<style>#delete-action{display: none;}</style>';
        echo $style;
    }
}
add_action('admin_print_styles', 'admin_preview_delete_css_custom');

カスタム投稿タイプ名が「company」と「office」の時はプレビューとゴミ箱へ移動を非表示にするようにしている。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?