먼저 자신의 사진 크기를 만들어야합니다. 이것은 add_image_size() 기능으로 수행됩니다.
당신은 이런 식으로 작업을 수행 할 수는 있지을 경우
if (function_exists('add_theme_support')) {
add_theme_support('post-thumbnails');
add_image_size('square-large', 300, 300, true); // name, width, height, crop
add_filter('image_size_names_choose', 'my_image_sizes');
}
function my_image_sizes($sizes) {
$addsizes = array(
"square-large" => __("Large square image")
);
$newsizes = array_merge($sizes, $addsizes);
return $newsizes;
}
이 테마 썸네일에 대한 지원을 추가합니다. 잘린 300x300 픽셀로 새로운 이미지 크기를 만듭니다. 두 번째 기능은 더 나은 설명을 제공하고 미디어 삽입 대화 상자에 표시되는지 확인합니다.
다음과 같이 사용할 수 있습니다.
<?php the_post_thumbnail('square-large'); ?>
테마를 functions.php
개 줄에 추가 할 수 있습니다. 테마가 업데이트 될 때이 줄을 덮어 쓰지 않으려면 하위 테마를 만드는 것이 좋습니다 (read here how to do that).
기존 이미지에는 영향을 미치지 않습니다. 누락 된 미리보기 이미지를 다음 코드로 다시 만들 수 있습니다.
include_once(ABSPATH . 'wp-admin/includes/image.php');
function regenerate_all_attachment_sizes() {
$args = array('post_type' => 'attachment', 'numberposts' => 100, 'post_status' => null, 'post_parent' => null, 'post_mime_type' => 'image');
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $post) {
$file = get_attached_file($post->ID);
wp_update_attachment_metadata($post->ID, wp_generate_attachment_metadata($post->ID, $file));
}
}
}
regenerate_all_attachment_sizes();
이 코드는 한 번만 실행하면됩니다.
"이 이미지를 사용하면 이미지가 사각형이 아닙니다"- "this"로 무엇을 의미합니까? –