该问题指的是如何在文章正文中添加自定义大小的图片。解决方法如下:
function custom_image_sizes() { add_image_size( 'custom-size', 800, 400, true ); } add_action( 'after_setup_theme', 'custom_image_sizes' );
这里的'custom-size'为图片尺寸的名称,可按需更改,800和400分别为图片的宽和高,可以根据自己的需求更改。最后的true表示:是否裁剪图片以匹配指定尺寸。若为false,则不裁剪图像,而是将图像按照给定的尺寸来显示。
在文章编辑器中,插入图像时,选择“自定义尺寸”选项,并选择“custom-size”。这将在文章正文中插入指定尺寸的图像。
注意:如果您希望应用这个尺寸到已有的图片,使用 regenerate thumbnails 插件可以解决这个问题。
代码示例:
function custom_image_sizes() { add_image_size( 'custom-size', 800, 400, true ); } add_action( 'after_setup_theme', 'custom_image_sizes' );
// 在文章中使用以下方式
//