缩略图在WordPress中自动裁剪

时间:2018-03-06 08:19:02

标签: wordpress image

我将此代码用于显示页面缩略图

<?php the_post_thumbnail('thumbnail', array('class' => 'img-responsive')); ?>

但图像从1290px * 400px到150px * 150px

我将以下代码添加到functions.php但问题未解决

function remove_image_size_attributes( $html ) {
    return preg_replace( '/(width|height)="\d*"/', '', $html );
}

// Remove image size attributes from post thumbnails
add_filter( 'post_thumbnail_html', 'remove_image_size_attributes' );

// Remove image size attributes from images added to a WordPress post
add_filter( 'image_send_to_editor', 'remove_image_size_attributes' );

2 个答案:

答案 0 :(得分:0)

你有:

<?php the_post_thumbnail('thumbnail', array('class' => 'img-responsive')); ?>

所以你的图像大小,缩略图大小。要获得完整图片尺寸,请尝试给出:

<?php the_post_thumbnail('full', array('class' => 'img-responsive')); ?>

或者你也可以显示这样的图像

<?php $url = get_the_post_thumbnail_url( $post_id, 'full' ); ?>

<img src="<?php echo $url;" ?>

答案 1 :(得分:0)

更改

<?php the_post_thumbnail('thumbnail', array('class' => 'img-responsive')); ?>

<?php the_post_thumbnail('full', array('class' => 'img-responsive')); ?>

或者你也可以显示这样的图像

<?php $url = get_the_post_thumbnail_url( $post_id, 'full' ); ?>

<img src="<?php echo $url;" ?>
相关问题