Skip to content

Commit

Permalink
Hide title functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
skysarwer committed Jan 24, 2023
1 parent d17ec5e commit 4e9b1fc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 32 additions & 0 deletions inc/template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,35 @@ function evn_pingback_header() {
}
}
add_action( 'wp_head', 'evn_pingback_header' );

function evn_add_hide_title_metabox() {
add_meta_box(
'hide_title_metabox', // Metabox ID
'Hide Title', // Metabox title
'evn_render_hide_title_metabox', // Callback function to render the metabox
'page', // Post type
'side', // Context (normal, advanced, or side)
'default' // Priority (high, core, default, or low)
);
}
add_action( 'add_meta_boxes', 'evn_add_hide_title_metabox' );

function evn_render_hide_title_metabox( $post ) {
$hide_title = get_post_meta( $post->ID, 'hide_title', true );

?>
<label for="hide_title">
<input type="checkbox" name="hide_title" id="hide_title" value="1" <?php checked( $hide_title, 1 ); ?>>
Hide Title
</label>
<?php
}

function evn_save_hide_title_metabox( $post_id ) {
if ( isset( $_POST['hide_title'] ) ) {
update_post_meta( $post_id, 'hide_title', 1 );
} else {
update_post_meta( $post_id, 'hide_title', 0 );
}
}
add_action( 'save_post', 'evn_save_hide_title_metabox' );
4 changes: 2 additions & 2 deletions template-parts/content-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<?php if (!is_front_page()) :?>
<?php if ( !is_front_page() && get_post_meta($id, 'hide_title' , true) != 1 ) :?>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<?php endif;?>
<?php endif; ?>

<?php evn_post_thumbnail(); ?>

Expand Down

0 comments on commit 4e9b1fc

Please sign in to comment.