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 = array(
    'source' => 'cf/photo_url',
    'settings' => array(
        '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

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 );

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 );

More examples