The MH Magazine Lite WordPress theme removed the Subheading Post Option between version 2.0.5 and 2.1.0 of the theme. The release notes indicates MH Themes “Removed custom meta field for subheading to meet WordPress.org guidelines” ( readme.txt ). Note that only the code was changed: Any existing meta data is still resident in your wp_postmeta table.
How can you restore the display of the metadata, and ability to add/modify the metadata?
- If you do not have a child theme, create one. The following three changes will be made in your child theme.
- In your functions.php, add this code:
/* themes/mh-magazine-lite/includes/mh-custom-functions.php Parent theme update from 2.0.5 to 2.1.0 disabled subheadings. Add them back in. https://themes.trac.wordpress.org/changeset?old_path=%2Fmh-magazine-lite%2F2.0.5%2Fincludes%2Fmh-custom-functions.php&old=54854&new_path=%2Fmh-magazine-lite%2F2.1.0%2Fincludes%2Fmh-custom-functions.php&new=55985&sfp_email=&sfph_mail= https://themes.trac.wordpress.org/changeset/54854/mh-magazine-lite/2.0.5/readme.txt?old=55985&old_path=%2Fmh-magazine-lite%2F2.1.0%2Freadme.txt */ if (!function_exists('mh_magazine_lite_subheading')) { function mh_magazine_lite_subheading() { global $post; if (get_post_meta($post->ID, "mh-subheading", true)) { echo '<div class="mh-subheading-top"></div>' . "\n"; echo '<h2 class="mh-subheading">' . esc_attr(get_post_meta($post->ID, "mh-subheading", true)) . '</h2>' . "\n"; } } } add_action('mh_post_header', 'mh_magazine_lite_subheading');
- In your functions.php, also add this code:
/* themes/mh-magazine-lite/admin/admin.php Parent theme update from 2.0.5 to 2.1.0 disabled subheadings. Add them back in. https://themes.trac.wordpress.org/changeset/54854/mh-magazine-lite/2.0.5/admin/admin.php?contextall=1&old=55985&old_path=%2Fmh-magazine-lite%2F2.1.0%2Fadmin%2Fadmin.php https://themes.trac.wordpress.org/changeset/54854/mh-magazine-lite/2.0.5/readme.txt?old=55985&old_path=%2Fmh-magazine-lite%2F2.1.0%2Freadme.txt */ /***** Custom Meta Boxes *****/ if (!function_exists('mh_add_meta_boxes')) { function mh_add_meta_boxes() { add_meta_box('mh_post_details', esc_html__('Post Options', 'mh-magazine-lite'), 'mh_post_options', 'post', 'normal', 'high'); } } add_action('add_meta_boxes', 'mh_add_meta_boxes'); if (!function_exists('mh_post_options')) { function mh_post_options() { global $post; wp_nonce_field('mh_meta_box_nonce', 'meta_box_nonce'); echo '<p>'; echo '<label for="mh-subheading">' . esc_html__("Subheading (will be displayed below post title)", 'mh-magazine-lite') . '</label>'; echo '<br />'; echo '<input class="widefat" type="text" name="mh-subheading" id="mh-subheading" placeholder="Enter subheading" value="' . esc_attr(get_post_meta($post->ID, 'mh-subheading', true)) . '" size="30" />'; echo '</p>'; } } if (!function_exists('mh_save_meta_boxes')) { function mh_save_meta_boxes($post_id, $post) { if (!isset($_POST['meta_box_nonce']) || !wp_verify_nonce($_POST['meta_box_nonce'], 'mh_meta_box_nonce')) { return $post->ID; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post->ID; } if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post->ID; } } elseif (!current_user_can('edit_post', $post_id)) { return $post->ID; } if ('post' == $_POST['post_type']) { $meta_data['mh-subheading'] = esc_attr($_POST['mh-subheading']); } foreach ($meta_data as $key => $value) { if ($post->post_type == 'revision') return; $value = implode(',', (array)$value); if (get_post_meta($post->ID, $key, FALSE)) { update_post_meta($post->ID, $key, $value); } else { add_post_meta($post->ID, $key, $value); } if (!$value) delete_post_meta($post->ID, $key); } } } add_action('save_post', 'mh_save_meta_boxes', 10, 2 );
- In your style.css, add this code:
/* themes/mh-magazine-lite/style.css Parent theme update from 2.0.5 to 2.1.0 disabled subheadings. Add them back in. https://themes.trac.wordpress.org/changeset?old_path=%2Fmh-magazine-lite%2F2.0.5%2Fstyle.css&old=54854&new_path=%2Fmh-magazine-lite%2F2.1.0%2Fstyle.css&new=55985&sfp_email=&sfph_mail= https://themes.trac.wordpress.org/changeset/54854/mh-magazine-lite/2.0.5/readme.txt?old=55985&old_path=%2Fmh-magazine-lite%2F2.1.0%2Freadme.txt */ .mh-subheading-top { margin-top: 10px; border-bottom: 3px solid #2a2a2a; } .mh-subheading { display: inline-block; font-size: 13px; font-size: 0.8125rem; color: #fff; padding: 5px 10px; margin-bottom: 10px; margin-bottom: 0.625rem; background: #e64946; text-transform: uppercase; }
Note that the first line in each comment indicates the source file the snippet was originally located in. The second line indicates the reason for the change. The third line is the URL showing the diff between release 54854 (v2.0.5) and 55985 (v2.1.0). The final comment line is the URL for the release notes diff.
It took me seven hours to figure out why my meta had gone missing, and how to fix it. Hopefully this saves you the pain & aggravation I went through.