Custom image size for custom post type in Wordpress

I am trying to add custom image size to custom message type messages articlesby executing the following function in functions.php:

function thumb_size($id)
{
    if(get_post_type() == "articles")
    {
        add_image_size('articles-thumb', 113, 72, true);
    }
}
add_action ( 'publish_post', 'thumb_size' );

and try to show it with the following code:

the_post_thumbnail('articles-thumb');

But what I see as output is not the same size as me, what is the problem?

+5
source share
3 answers

Just use a single line add_image_size('articles-thumb', 113, 72, true);in the functions.php file. Remove the reset of your function and add the action code.

Then display it in the line asked in the question. the_post_thumbnail('articles-thumb');

. : http://wordpress.org/extend/plugins/regenerate-thumbnails/ , , . . .

+2

, , . "", 2 , , ? .

+6

After uploading any image to WordPress, 3 default sizes are created for the image. Thumbnail Medium size Large size Stop any user to use the sizes of these images for the current theme, use this code in your functions.php folder inside the folder. Delete them using the WordPress middle_image_sizes_advanced action, then undo the thumbnails, medium and large sizes, which means that only the size of the full image remains.

function w3learn_filter_image_sizes( $sizes) {

    unset( $sizes['thumbnail']);
    unset( $sizes['medium']);
    unset( $sizes['large']);

    return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'w3learn_filter_image_sizes');`

Information about my Delete default media image sizes in Wordpress

+1
source

All Articles