Skip to content

Instantly share code, notes, and snippets.

@atanas-dev
Created October 21, 2019 13:20
Show Gist options
  • Save atanas-dev/da91179362d5ff8d1645e45124b6a267 to your computer and use it in GitHub Desktop.
Save atanas-dev/da91179362d5ff8d1645e45124b6a267 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 );
@mklasen
Copy link

mklasen commented Apr 2, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment