サムネイル用としてカスタム画像を作りたいとき、そして利用するときのメニュータブを増やす方法
以下の内容をfunction.phpに追加する。
カスタムサムネイル画像
function add_custom_image_sizes() {
global $custom_image;
$custom_image = array(
'small' => array(
'name' => 'カスタムサイズ',
'width' => 190,
'height' => 9999, //横に対して比率で縦を自動に設定
'selectable' => true
),
);
foreach ( $custom_image as $slug => $size ) {
add_image_size( $slug, $size['width'], $size['height']);
}
}
add_action( 'after_setup_theme', 'add_custom_image_sizes' );
メディア追加でサイズの選択タブを追加する
function add_custom_image_size_select( $size_names ) {
global $custom_image;
$custom_size = get_intermediate_image_sizes();
foreach ( $custom_size as $size ) {
if ( isset( $custom_image[$size]['selectable'] ) && $custom_image[$size]['selectable'] ) {
$size_names[$size] = $custom_image[$size]['name'];
}
}
return $size_names;
}
add_filter( 'image_size_names_choose', 'add_custom_image_size_select' );