I would like to change the "Image style" of some Image fields in some given view modes, which are attached to particular content types; I would like to do this programmatically.

This is what I would like to change:

Changing the Image style of an Image field in a given view mode

How should I do this?

1 Answer 1


Something like this should do it:

$entity_type = 'node';
$bundle = 'article';
$field_name = 'field_image';
$view_mode = 'default';

// Get the instance info
$instance_info = field_info_instance($entity_type, $field_name, $bundle);

// Change the image style
$instance_info['display'][$view_mode]['settings']['image_style'] = 'new_image_style';

// Save it
  • Where could I place this code? in template.php? or where? thanks.
    – SaidbakR
    Sep 6, 2015 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.