Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fahimxyz/6500939bd1cf66bdcb6f0134525cd8f3 to your computer and use it in GitHub Desktop.
Save fahimxyz/6500939bd1cf66bdcb6f0134525cd8f3 to your computer and use it in GitHub Desktop.
<?php
// Make sure you replace the following in the example:
// - META_KEY_HERE
// - LABEL_HERE
// - VISUAL_GROUP_LABEL_HERE
// Register your new Dynamic Content fields:
add_filter( 'et_builder_custom_dynamic_content_fields', function ( $custom_fields, $post_id, $raw_custom_fields ) {
$custom_fields['custom_meta_META_KEY_HERE'] = array(
'label' => esc_html( 'LABEL_HERE' ),
'type' => 'any', // 'text', 'image', 'url' or 'any'
'fields' => array(
// You can skip these if they are not needed:
'before' => array(
'label' => esc_html__( 'Before', 'et_builder' ),
'type' => 'text',
'default' => '',
'show_on' => 'text',
),
'after' => array(
'label' => esc_html__( 'After', 'et_builder' ),
'type' => 'text',
'default' => '',
'show_on' => 'text',
),
),
'meta_key' => 'META_KEY_HERE',
'custom' => true,
'group' => 'VISUAL_GROUP_LABEL_HERE',
);
return $custom_fields;
}, 10, 3 );
// If you need to format your value before it's displayed add this:
add_filter( 'et_builder_dynamic_content_meta_value', function ( $meta_value, $meta_key, $post_id ) {
if ( 'META_KEY_HERE' === $meta_key ) {
// Format your value here ...
}
return $meta_value;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment