1
1

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 5 years have passed since last update.

WordPressのメディア追加、アップロード時に選択肢を制限する方法

Posted at

WordPressのメディアの追加の画面って、なんか無駄なもんが多くて、使いにくいなーって思ってたんすよね。
まぁ自分が使う分には、我慢すればいいだけだけど(とはいえ気持ち悪い)、
お客さんにさぁどうぞってやるには、やや雑ですよね。

そこで、選択肢を制限する方法です。
CSSで見えないようにしてるだけなんですがw

functions.php
// メディアアップロード時の選択肢を制限
add_action( 'admin_print_styles', 'admin_css_custom' );
function admin_css_custom() {
  // "hoge"というカスタム投稿タイプだけに適用。
  global $post;
  if(!isset($post) || "hoge" != $post -> post_type){
    return;
  }
  echo '
    <style>
      .attachment-details label[data-setting="caption"],
      .attachment-details label[data-setting="description"],
      div.attachment-display-settings .alignment option[value="center"],
      div.attachment-display-settings .alignment option[value="none"],
      div.attachment-display-settings .setting:nth-child(3),
      div.attachment-display-settings .setting:nth-child(4)
      {display: none;}
    </style>';
}

上から、
使いみちがあんまりない「キャプション」、「説明」、
「配置」の選択肢の「中央」と「なし」
そして、「リンク先」、「サイズ」

これに合わせて、画像の自動生成にも制限をかけておきました。
デフォルトで生成される「中サイズ」と「大サイズ」も不要そうだったので、
メディア設定
メディア設定の中サイズと大サイズの数値を削除しておきました。
そうすることで、生成されないし、選択肢にも出てこなくなる、って寸法。

あと、前半に書いてある処理は、特定のカスタム投稿タイプのみに適用させる処理。

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?