Skip to content

Instantly share code, notes, and snippets.

@MjHead
Last active March 6, 2018 11:00
Show Gist options
  • Save MjHead/ce52499b041a5a1f6fc1fc965a6156a0 to your computer and use it in GitHub Desktop.
Save MjHead/ce52499b041a5a1f6fc1fc965a6156a0 to your computer and use it in GitHub Desktop.
Add own callback function for meta controls in Smart List for JetBlog
<?php
/**
* Add callback function for date formatting into available callbacks list in control.
*/
function my_update_meta_controls( $widget ) {
foreach ( array( 'title_related', 'content_related' ) as $position ) {
$control = $widget->get_controls( $position . '_meta' );
$control['fields'][3]['options'] = array_merge(
$control['fields'][3]['options'],
array( 'my_date_format' => 'my_date_format' )
);
$widget->update_control( $position . '_meta', $control );
}
}
add_action(
'elementor/element/jet-blog-smart-listing/section_custom_fields/before_section_end',
'my_update_meta_controls',
10
);
/**
* Formatting date callback
*/
function my_date_format( $timestamp ) {
// Change format as you need
$format = 'F j, Y';
$date = DateTime::createFromFormat( 'Ymd', $timestamp );
return $date->format( $format );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment