Wordpress custom thumbnail size

后端 未结 2 1970
北海茫月
北海茫月 2021-01-22 01:31

I\'am trying to make custom thumbnail sizes in Wordpress. Currently I have following code in functions.php



        
2条回答
  •  佛祖请我去吃肉
    2021-01-22 01:57

    According to add_image_size() in the Documentation:
    Add this to your theme's functions.php :

    add_action( 'after_setup_theme', 'mytheme_custom_thumbnail_size' );
    function mytheme_custom_thumbnail_size(){
        add_image_size( 'thumb-small', 200, 200, true ); // Hard crop to exact dimensions (crops sides or top and bottom)
        add_image_size( 'thumb-medium', 520, 9999 ); // Crop to 520px width, unlimited height
        add_image_size( 'thumb-large', 720, 340 ); // Soft proprtional crop to max 720px width, max 340px height
    }
    

    To display a featured image with your new size (in this case “thumb-small”) in a post, just add:

    
    

    If your theme does not support featured images, you need to add this to your functions.php as well, inside of your setup function.

    // Enable featured image
    add_theme_support( 'post-thumbnails' );
    

    If you add new thumbnail sizes to a site which already has media uploaded, you’ll need to regenerate thumbnails once for the new sizes to show up using this plugin:

    Regenerate Thumbnails

提交回复
热议问题