More characters for the alternative text field in Contao 4

This is an archive post. It will not be updated.

Contao 4 limits the database field for the alternative text of images to 255 characters. When online editors write high-quality alternative texts to improve accessibility, this is often not enough. Fortunately, this is easy to fix.

On the web space, create a file named tl_content.php in the folder /app/Resources/contao/dca/. If the folder structure below app/ doesn’t exist yet on your installation, you can add these directories via FTP or SSH. Mind the capital R in Resources.

Add these lines to the file tl_content.php:

<?php
$GLOBALS['TL_DCA']['tl_content']['fields']['caption']['sql']="text NULL";
$GLOBALS['TL_DCA']['tl_content']['fields']['caption']['eval']['maxlength'] = 1000;

This tells Contao 4 that the field is assigned more space, so that Contao allows more characters to be entered.

Now you also have to correct the field in the database so that it can actually hold more. Open the database structure, e.g. with phpMyAdmin, switch to the database table tl_content and there, for the field caption, change the type to text and the value to NULL.

Finally, log in to the Contao Manager and click on “Maintenance” in the menu. In the “Application Cache” section, clear the cache. Alternatively, you can of course also do this directly via SSH without the Contao Manager.

That’s it! Contao now knows that the field for alternative texts may have more characters, and the database can handle correspondingly more characters.