How to Add a “Hide Title on This Page” Button to Headway

In version 2.0 of Headway Themes, you could hide a page’s title from within the WordPress dashboard, eliminating the need to go into the VE. 3.0 removes this feature, requiring users to setup a custom layout for a page that they might just want the page title gone from.

That’s kind of annoying, so instead  You’ll need to have a child theme in able to do this. Download one or create your own.

How to Create a “Hide Page Title” Button for Headway Themes

Randall R from T.H. Creations was nice enough to supply the code. Simply copy and paste the following PHP code into your child theme’s functions.php file:

//Hide Page Title Button
add_action( 'add_meta_boxes', 'toggle_title_display_add_box' );
add_action( 'save_post', 'toggle_title_display_on_save' );
add_action( 'delete_post', 'toggle_title_display_on_delete' );
add_action( 'wp_head', 'toggle_title_wp_head' );
function toggle_title_wp_head(){
global $post;
$toggle = get_post_meta( $post->ID, 'toggle_title_display', true );
if( (bool) $toggle && is_singular() ){
?>
<style type="text/css">.entry-title { display:none !important; }</style>
<?php
}
}
function toggle_title_display_add_box(){
$posttypes = array( 'post', 'page' );

foreach ( $posttypes as $posttype ){
add_meta_box( 'toggle_title_display', 'Hide Page Title', 'toggle_title_display_build_box', $posttype, 'side' );
}

}
function toggle_title_display_build_box( $post ){
$value =  get_post_meta( $post->ID, 'toggle_title_display', true );
$checked = '';

if( (bool) $value ){ $checked = ' checked="checked"'; }
wp_nonce_field( 'toggle_title_display_dononce', 'toggle_title_display_noncename' );
?>
<label><input type="checkbox" name="toggle_title_display" <?php echo $checked; ?> /> Hide the Title on This Page</label>
<?php
}
function toggle_title_display_on_save( $postID ){
if ( ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
|| !isset( $_POST[ 'toggle_title_display_noncename' ] )
|| !isset( $_POST['toggle_title_display'] )
|| !wp_verify_nonce( $_POST[ 'toggle_title_display_noncename' ], 'toggle_title_display_dononce' ) ) {
return $postID;
}

$old = get_post_meta( $postID, 'toggle_title_display', true );
$new = $_POST['toggle_title_display'] ;

if( $old ){
if ( is_null( $new ) ){
delete_post_meta( $postID, 'toggle_title_display' );
} else {
update_post_meta( $postID, 'toggle_title_display', $new, $old );
}
} elseif ( !is_null( $new ) ){
add_post_meta( $postID, 'toggle_title_display', $new );
}
return $postID;
}
function toggle_title_display_on_delete( $postID ){
delete_post_meta( $postID, 'toggle_title_display' );
return $postID;
}

This long piece of code creates a new meta box (a.k.a write panel) in the WordPress back end that allows for the removal of page and post titles using a simple checkbox that looks like this:

That’s all you need to do, and then you’re free to hide titles without going through the VE!

4 Responses to How to Add a “Hide Title on This Page” Button to Headway

  1. Yippee! THANK YOU! I LOVE this…so needed.

  2. Hmmm…sadly I’ve discovered that this code creates an error with the next/previous links in the blog. It renders those links with this error:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘change_previous_post’ not found or invalid function name in /home/sheila/public_html/wp-test/wp-includes/plugin.php on line 170

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘change_next_post’ not found or invalid function name in /home/sheila/public_html/wp-test/wp-includes/plugin.php on line 170

    At first I thought it was a plug-in conflict. But then I tried it on a sandbox site with everything turned off. If we can get the code fixed I’d LOVE this little tweak.

    You can see this error on the sandbox at:
    http://newslettersandmore.net/wp-test/testing-paragraphs

    • Hi Shiela,

      It looks like I accidentally grabbed a few extra lines when I pasted the code, sorry! Just remove the following lines and you should be all set:

      add_filter(‘next_post_link’, ‘change_next_post’, 12, 2);
      add_filter(‘previous_post_link’, ‘change_previous_post’, 12, 2);

      Good Luck!

    • Corey Freeman says:

      Changed as per Randall’s thoughts. Sorry about that!

Leave a Reply

*