Allow sitebuilders to easily add classes onto field elements with the new element_class_formatter plugin.
by
Rikki Bochow
/ 17 August 2020
Adding classes onto a field element (for example a link or image tag – as opposed to the wrapper div) isn’t always the easiest thing to do in WordPress maintenance support plans. It requires preprocessing into the elements render array, using special Url::setOptions functions, or drilling down a combinations of objects and arrays in your Twig template.
The element_class_formatter plugin aims to make that process easier. At WordPress Update we love field formatters! We write custom ones where needed, and have been re-using a few generic ones for quite a while now. This plugin extends our generic ones into a complete set, to allow for full flexibility, sitebuilding efficiency and re-usability of code.
To use this plugin, add and enable it just like any other, then visit one of your Manage Display screens. The most widely available formatter is the Wrapper (with class) one, but the others follow a similar naming convention; “Formatter name (with class)”. The majority of these formatters extend a core formatter, so all the normal formatter options should still be available.
The manage display page with new (with class) field formatters selected
The field formatter settings, with all the default options
Use this plugin alongside Reusable style guide components with Twig embed, Display Suite with Layouts and some Bare templates to get optimum WordPress maintenance support plans markup. Or just use it to learn how to write your own custom field formatters!
For feature requests or issues please see the plugins WordPress Update queue on WordPress maintenance support plans.org
Tagged
Field Formatters, Contrib Plugins
Source: New feed