Php 如何使用wordpress update_option()函数修改中大图像deafult';s宽度
在最近的wordpress版本中,添加了一个新的默认中间尺寸“中大”,以更好地利用响应图像支持。默认情况下,新尺寸为768px宽,没有高度限制 选择要插入帖子的图像时,UI中不包括中大尺寸,也不包括从“媒体设置”页面更改图像大小的UI。但是,开发人员可以使用update_option()函数修改此新大小的宽度,类似于任何其他默认图像大小 用法:Php 如何使用wordpress update_option()函数修改中大图像deafult';s宽度,php,html,wordpress,Php,Html,Wordpress,在最近的wordpress版本中,添加了一个新的默认中间尺寸“中大”,以更好地利用响应图像支持。默认情况下,新尺寸为768px宽,没有高度限制 选择要插入帖子的图像时,UI中不包括中大尺寸,也不包括从“媒体设置”页面更改图像大小的UI。但是,开发人员可以使用update_option()函数修改此新大小的宽度,类似于任何其他默认图像大小 用法: <?php update_option( $option, $new_value, $autoload ); ?> } 添加过滤器('im
<?php update_option( $option, $new_value, $autoload ); ?>
}
添加过滤器('image\u resize\u dimensions','filter\u image\u resize\u dimensions',10,6) 使用
wp\u calculate\u image\u srcset()
时,过滤器max\u srcset\u image\u width
不会更改图像大小的最大宽度,而是更改srcset的最大宽度
要更改WordPress预定义图像的大小,您需要使用图像\u resize\u dimensions
,您可以阅读所有详细信息
更新
根据您给定的代码,这里有一些关于它的更正
function filter_image_resize_dimensions( $payload, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
if ( $orig_h === 300 ) {
$new_w = 200; // you are checking for height and setting width ??
$new_h = $orig_h; // you must define it to return a value, but here there's no change...
}
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}
add_filter( 'image_resize_dimensions', 'filter_image_resize_dimensions', 10, 6 );
希望有帮助我以这种方式重试,但再次失败:函数filter\u image\u resize\u dimensions($max\u-width,$size\u-array){if($size\u-array[0]==300){$max\u-width=200;}返回$max\u-width;}添加过滤器('image\u-resize\u-dimensions',filter\u-image\u-resize\u-dimensions',10,2);参数 由于回调函数与前面的函数不同,请阅读我的链接上的提供示例,这里没有$size\u数组,而是$orig\u h,$orig\u w。更改您的条件语句并将筛选器max args更改为6,它应该可以工作。如果($orig_h>200){$new_w=200;$new_h=auto;}--这段代码正确吗?(我想将宽度调整为200,高度自动调整为200,但根据调整后的宽度按比例调整)这取决于您的主题(或插件),上载图像时,WordPress会根据声明的图像大小保存不同的大小,并使用add_image_size()函数启动,您可以使用函数remove_image_size轻松删除任何图像大小(但需要找到其slug才能正确删除),还可以通过过滤器修改add_image_size参数。
function filter_image_resize_dimensions( $payload, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
if ( $orig_h === 300 ) {
$new_w = 200; // you are checking for height and setting width ??
$new_h = $orig_h; // you must define it to return a value, but here there's no change...
}
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}
add_filter( 'image_resize_dimensions', 'filter_image_resize_dimensions', 10, 6 );