Adding a custom field to conditionally display last modified date:
You can use the built-in custom fields metabox of your post. Usually it is hidden by default, so you have to enable it going to ‘Screen Options ‘ and checking the ‘Custom Fields’ box like this:
If you’re using the new block editor, you’ll find the option by going to the Edit Post Screen > Click the three dots button on the top right corner > Settings > Advanced Panels.
Now, add a new custom field, let’s call it show_last_modified
and set it to true.
Displaying the last modified date:
The function the_modified_date()
will give you the date on which the post was last modified.
To display it, seems that you will have to override the mh_magazine_post_meta()
function.
function mh_magazine_post_meta() {
$mh_magazine_options = mh_magazine_theme_options();
if ($mh_magazine_options['post_meta_date'] === 'enable' || $mh_magazine_options['post_meta_author'] === 'enable' && in_the_loop() || $mh_magazine_options['post_meta_cat'] === 'enable' && in_the_loop() && is_singular() || $mh_magazine_options['post_meta_comments'] === 'enable') {
echo '<div class="mh-meta entry-meta">' . "\n";
if ($mh_magazine_options['post_meta_date'] === 'enable') {
echo '<span class="entry-meta-date updated"><i class="fa fa-clock-o"></i><a href="' . esc_url(get_month_link(get_the_time('Y'), get_the_time('m'))) . '">' . get_the_date() . '</a></span>' . "\n";
// Custom code
if(!empty(get_post_meta(get_the_ID(), 'show_last_modified', true)){
echo 'Last modified date:' . the_modified_date();
}
//
}
if ($mh_magazine_options['post_meta_author'] === 'enable' && in_the_loop()) {
echo '<span class="entry-meta-author author vcard"><i class="fa fa-user"></i><a class="fn" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></span>' . "\n";
}
if ($mh_magazine_options['post_meta_cat'] === 'enable' && in_the_loop() && is_singular()) {
echo '<span class="entry-meta-categories"><i class="fa fa-folder-open-o"></i>' . get_the_category_list(', ', '') . '</span>' . "\n";
}
if ($mh_magazine_options['post_meta_comments'] === 'enable') {
echo '<span class="entry-meta-comments"><i class="fa fa-comment-o"></i>';
mh_magazine_comment_count();
echo '</span>' . "\n";
}
echo '</div>' . "\n";
}
}
add_action('mh_post_header', 'mh_magazine_post_meta');
Place the above code on your child theme and customize the markup to suit your needs.