Is there a way to bulk update image title and alt tags? Where do alt and title tags are saved in the database?


Rewriting the D7 code of How to bulk update image alt and title?

$nodes = \Drupal::entityTypeManager()
  ->loadByProperties(['type' => 'article']);

foreach ($nodes as $node) {
  $node->field_image->alt = $alt;
  $node->field_image->title = $title;

  • Is there a way to uniquely identify the image of a node? Because I need to import those from a csv file. Sep 18 '18 at 6:52
  • Sure, if for example the filenames match you can check $node->field_image->entity->filename->value
    – 4k4
    Sep 18 '18 at 7:03
  • $node->field_image->alt = $alt; doesn't change the value. Sep 25 '18 at 5:45
  • This example is for the core content type article. Debug $node->toArray(), here you'll should find the properties alt and title of an image field in your content type.
    – 4k4
    Sep 25 '18 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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