Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 'Custom Hide Post Title Tick Box' field below post editor
- add_action('admin_menu', 'custom_hide_post_title');
- add_action('save_post', 'save_custom_hide_post_title');
- function custom_hide_post_title() {
- add_meta_box('custom_hide_post_title', 'Hide Post Title', 'custom_hide_post_title_input_function', 'post', 'normal', 'high');
- }
- function custom_hide_post_title_input_function() {
- global $post;
- echo '<input type="hidden" name="custom_hide_post_title_input_hidden" id="custom_hide_post_title_input_hidden" value="'.wp_create_nonce('custom-hide_post_title-nonce').'" />';
- echo '<span style="display:inline-block;">Tick to hide this post title in archives and in the single post: </span><input type="checkbox" name="custom_hide_post_title_input" id="custom_hide_post_title_input" '.((get_post_meta($post->ID,'_custom_hide_post_title',true)==true)?' checked="checked"':'').'" />';
- }
- function save_custom_hide_post_title($post_id) {
- if (!wp_verify_nonce($_POST['custom_hide_post_title_input_hidden'], 'custom-hide_post_title-nonce')) return $post_id;
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
- $custom_hide_post_title = isset($_POST['custom_hide_post_title_input']);
- update_post_meta($post_id, '_custom_hide_post_title', $custom_hide_post_title);
- }
- add_filter('the_title','hide_some_post_title');
- function hide_some_post_title($title) {
- if( !is_admin() && in_the_loop() ) {
- global $post;
- if( get_post_meta($post->ID,'_custom_hide_post_title',true) ) $title = '';
- }
- return $title;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement