Sometimes we need to custom format the post meta field in Custom Post Builder Plugin’s template.
For example, formatting a website url post meta to an anchor tag or formatting a phone number post meta value to a clickable phone anchor tag.
The ACF Field Divi Module outputs a WordPress post meta field on the page. This module ships with inbuilt formatters.
The Custom Post Builder plugin provides a WordPress filter – df_acf_formatter_callbacks to register formatter callbacks
Creating Formatter Filter
Custom Post Builder provides a filter hook df_acf_formatter_callbacks. This hook registers the custom field formatter callbacks.
A field formatter callback is a php function that takes two input arguments
- fieldValue : This is the value of the post meta choosen in the ACF Field Divi Module
- attrs : This is an array of attributes using data from Additional Shortcode Attributes in the ACF Field Divi Module.
Below is sample filter code for formatting a website url to html link and phone number text to clickable html link. It is highly recommended that you write this filter in a child theme
Setting Custom Formatter in ACF Field Module
It’s time to link your field formatter to a post meta in the ACF Field Divi Module
We are going to link the phone post meta field to the phone_number field formatter callback.
The screenshot depicts the choice below