Hide Blog Date & Add Page Setting to Conditionally Enable It
// Add new page setting
add_filter( 'wpex_metabox_array', function( $options, $post ) {
// Add new setting to main tab for blog posts only
if ( 'post' != get_post_type( $post ) ) {
return $options;
}
// Add new setting
$options['main']['settings']['wpex_display_date'] = array(
'title' => __( 'Show Date?', 'wpex' ),
'description' => __( 'Display date on entries and posts', 'wpex' ),
'id' => 'wpex_display_date',
'type' => 'select',
'options' => array(
'' => __( 'No', 'wpex' ), // Default is no so it has an empty value
'yes' => __( 'Yes', 'wpex' ),
),
);
// Return all options
return $options;
}, 2, 20 );
// Show hide date
function wpex_blog_meta_sections( $sections ) {
// Check meta option to display date if not remove
if ( 'yes' != get_post_meta( get_the_ID(), 'wpex_display_date', true ) ) {
unset( $sections['date'] );
}
// Return sections
return $sections;
}
add_filter( 'wpex_blog_entry_meta_sections', 'wpex_blog_meta_sections' );
add_filter( 'wpex_blog_single_meta_sections', 'wpex_blog_meta_sections' );
All PHP snippets should be added via child theme's functions.php file or via a plugin (we recommend Code Snippets)