When editing a body field with image and caption, the caption does not display during editing. Once saved it is visible - when the content is viewed.

Implementation-wise, I've added a caption field to the Image entity via the Entity View Mode config pages - admin/structure/file-types/manage/image/fields

Any thoughts on how to get the caption to show during edit?

CKEditor 4.3 supports captions but there would need to be support for the Drupal side of the implementation.

  • Hey, I have two questions: 1) Do you need the caption when you're just attaching the image to the node or when you're embedding it into the body with the CKEditor image button? And 2) when you say image caption, you're not talking about the image alt attribute, are you? – Boriana Ditcheva Dec 12 '13 at 17:59
  • Thanks @Boriana for your interest in this question, my answers to your questions: 1) I don't use the image with the node like this, I use the Wysiwyg button for image to embed the image in the edit area. On clicking the button it asks for image source e.g. upload, library, etc. and then the caption. 2) Correct. I've added a caption field to the image entity by visiting the admin page admin/structure/file-types/manage/image/fields as mentioned. – therobyouknow Dec 13 '13 at 10:45
  • Have you seen the video at vimeo.com/69750074? This is a demo of work being done for Drupal 8 but maybe you could back-port. See drupal.org/node/2027181. – user19292 Dec 16 '13 at 9:06
  • thanks it's a nice idea but I wasn't expecting to do a backport from Drupal 8 to solve my problem. I'd like to but I have limited time. I think I should explore other options, including my own answer before considering doing a backport – therobyouknow Dec 16 '13 at 9:15
  • hi, were u able to find a solution for ckeditor ? – vishal Jan 23 '14 at 16:48

As of CKEditor 4.3, they now have widgets in the CKEditor side. They have introduced the Image2 plugin/widget, which supports image captions. The problem I've seen here is that Drupal has not caught up with this, so if you're using the media module for a file browser, it looks like that functionality is not yet ported to this newer version. However, if you just care about captions, it works.

See: http://ckeditor.com/addon/image2 for the plugin. I've been using it with the CKEditor Module, but it should work just as fine with WYSIWYG + Ckeditor Library.

| improve this answer | |

I've been doing some more research and I gather you have gone down the Media/File Entity/Entity View Modes route as described at http://www.58bits.com/blog/2013/03/06/how-to-add-captions-to-images-in-drupal.

That seems a heck of a lot of work to go to in order to write a caption under an image and it is still not wysiwyg.

So here is another answer using Wysiwyg/TinyMCE and the dev version of Caption Filter. See discussion at https://drupal.org/node/696734. (Edit. There was some work done on integrating with CKEditor too but I don't think this has been committed although there are some patches, should it be important for you to stick with CKEditor.)

The upshot is as shown below. I was pleased to find I could put html in the caption. Example of image with caption in wysisyg editor.

| improve this answer | |
  • Thanks a lot but it does have to be CKEditor. I'm getting a little bit closer to a solution that involves media module filtering, either in its js or php. – therobyouknow Dec 16 '13 at 16:28

After discussing with my colleagues (thanks folks!), their idea for a solution is to write a filter for the JSON generated by the WYSIWYG.

The caption text is present in the JSON. So, extending the existing filter ought to be the solution.

| improve this answer | |

There are conflicts between the CKeditor Image2 plugin and Media module. If you're looking to align + caption your images while maintaining the media tag in your WYSIWYG, the most current recipe can be found here: https://www.drupal.org/node/2843391

| improve this answer | |

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.