facetwp_builder_item_value
Overview
This filter lets you modify the value of a Layout Builder item.
Parameters
- $value | mixed | The item value
- $item | array | An associative array of item data (see below)
$item = [ 'source' => 'cf/photo_url', 'settings' => [ 'prefix' => '', 'suffix' => '', 'is_hidden' => false, 'name' => 'photo_url', 'css_class' => '', /* other settings based on the item type */ ] ];
Within this hook, you also have access to the current post, e.g.
global $post; $post_id = $post->ID;
Usage
Example 1: Limit a Post Excerpt item to 120 characters:
add_filter( 'facetwp_builder_item_value', function( $value, $item ) { if ( 'post_excerpt' == $item['source'] ) { $value = substr( $value, 0, 120 ); } return $value; }, 10, 2 );
Example 2: Parse a shortcode within an HTML item named my-shortcode
:
add_filter( 'facetwp_builder_item_value', function( $value, $item ) { if ( 'my-shortcode' == $item['settings']['name'] ) { $value = do_shortcode( $value ); } return $value; }, 10, 2 );
Here’s where the “Name” field is located (when editing a layout builder item):
Example 3: output an array as a comma-separated string
add_filter( 'facetwp_builder_item_value', function( $value, $item ) { if ( is_array( $value ) ) { $value = implode( ', ', $value ); } return $value; }, 10, 2 );