1
0

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のカスタム投稿で新規投稿をできないようにする

Posted at

ワードプレスのテーマtwentytwentyoneを基盤に、カスタム投稿で新規投稿をできないようにする実装を行ったので、備忘録的にこの記事を残す。

環境情報

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

作業

functions.php に下記のコードを追加する

functions.php
// 新規追加ボタンの非表示化
function custom_edit_newpost_delete($hook) {
	if($hook == 'edit.php' || $hook == 'post.php'){
        $postType = get_post_type();
        if ( $postType == 'company' ) {
            echo '<style>.wrap .wp-heading-inline + .page-title-action{display: none;}</style>';
        }
	}
}
add_action('admin_enqueue_scripts', 'custom_edit_newpost_delete');

functions.php の args に下記のコードを追加する

functions.php
'capabilities' => array(
  'create_posts' => false,
),
'map_meta_cap' => true, //編集機能を残すために必要
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?