Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wordpress image crop
<?php
// in functions.php
add_theme_support( 'post-thumbnails');
/*
Wordpress crop an image = 5 size. Sizes are given below
thumbnail // Thumbnail (default 150px x 150px max)
medium // Medium resolution (default 300px x 300px max)
large // Large resolution (default 640px x 640px max)
full // Original image resolution (unmodified)
But, if you need custom size, you can define sizes in functions.php
*/
add_image_size( 'post-image', 600, 200, true );
// Using the sized image in your loop
// Image URL
// If you want to use wordpress resize just add your size, I've added large size image in example
$image_variable = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' ); echo $image_variable[0];
// If you want to use your custom size
$image_variable = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-image' ); echo $image_variable[0];
?>
@datause

This comment has been minimized.

Copy link

datause commented Aug 30, 2014

অনেক সুন্দর , আমাদের অনেক উপকারে আসবে 💃

@Rubel-hossain

This comment has been minimized.

Copy link

Rubel-hossain commented Dec 5, 2014

Awesome

@mdsalim

This comment has been minimized.

Copy link

mdsalim commented Jan 10, 2015

Really nice ..........thanks

@shahidulislamus

This comment has been minimized.

Copy link

shahidulislamus commented Jan 25, 2015

fine

@mofizul21

This comment has been minimized.

Copy link

mofizul21 commented May 19, 2015

I like it.

@kingRayhan

This comment has been minimized.

Copy link

kingRayhan commented Dec 17, 2015

চমৎকার হয়েছে

@safwanalamgir

This comment has been minimized.

Copy link

safwanalamgir commented Jun 16, 2016

add_new_image Hard Crop Not Working

pls rasel vai how to solve this problem

@prosantomazumder

This comment has been minimized.

Copy link

prosantomazumder commented Oct 14, 2017

Thanks Rasel vai..

@Sabuj6622

This comment has been minimized.

Copy link

Sabuj6622 commented Jan 15, 2018

Thanks Rasel vai.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.