Skip to content
Bill Erickson edited this page Mar 28, 2018 · 1 revision

Use on Posts or Custom Post Types

Genesis Title Toggle only applies to pages by default. You can enable it for posts or other custom post types using the be_title_toggle_post_types filter.

Example

/**
 * Add Genesis Title Toggle to Posts
 *
 * @see https://www.billerickson.net/code/genesis-title-toggle-for-posts
 * @author Bill Erickson
 *
 * @param array $post_types
 * @return array
 */
function be_title_toggle_on_posts( $post_types ) {
  $post_types[] = 'post';
  return $post_types;
}
add_filter( 'be_title_toggle_post_types', 'be_title_toggle_on_posts' );

Integrating with a custom theme

If your theme moves the location of the page title, you'll need to add some code to tell Genesis Title Toggle where it is and how to remove it.

Use the be_title_toggle_remove hook to run code when the title should be disabled. You can review these examples of customizations we've made for specific StudioPress themes.

Example

Let's say your theme removes the standard page title and adds a "page header" below the site header, like this:

/**
 * Page Header 
 *
 */
function be_page_header() {
	if( ! is_page() )
		return;

	// Remove default page header 
	remove_action( 'genesis_entry_header', 'genesis_do_post_title' );

	// Add our custom page header
 	echo '<div class="page-header"><div class="wrap">';
	genesis_do_post_title();
	echo '</div></div>';
}
add_action( 'genesis_after_header', 'be_page_header' );

When someone clicks "Hide Title", you expect this page header to be removed. Add the following to your child theme:

/**
 * Integrate with Genesis Title Toggle
 *
 * @see https://www.billerickson.net/code/genesis-title-toggle-theme-integration
 * @author Bill Erickson
 */
function be_integrate_genesis_title_toggle() {
	remove_action( 'genesis_after_header', 'be_page_header' );
}
add_action( 'be_title_toggle_remove', 'be_integrate_genesis_title_toggle' );