Reenabled Caption on Main-Article-Image

By admin_wla | Tue, 04/27/2021 - 09:34

In the Drupal 7 version the caption of the main article images was handelt by two bits:

  • The function hook_preprocess_image() in the theme to add the class "caption" to the image tag
  • The module image_caption which added a jQuery-Function to do the work

The module doesn't exist for Drupal 8. The preprocess_image hook luckily still is available.

  • With adding the function in the .theme-file of our theme, it was feasable to add the class "caption" to an image set by an image-field when the images style is w225xh150.
  • The jQuery-Function was put into the themes js directory into the file "drupal8_w3css_subtheme.theme". There the function worked as in the Drupal 7 version.

Mission accomplished

Caution: when in Drupal 10 jQuery is eliminated, the script has to be rewritten.

0
0