Black Friday Sale! Get up to $30 off GP Premium! Learn more ➝

Reply To: Full width title for specific categories and posts

Home Forums Support Full width title for specific categories and posts Reply To: Full width title for specific categories and posts

Home Forums Support Full width title for specific categories and posts Reply To: Full width title for specific categories and posts

#109462
Tom
Lead Developer
Lead Developer

Do-able! Tough, but do-able πŸ˜‰

First, we’ll remove the page title from a specific single post:

add_filter( 'the_title', 'generate_remove_post_titles', 10, 2 );
function generate_remove_post_titles( $title, $id = null )
{

	global $post, $generate_content_filter_completed;
	
	if ( $generate_content_filter_completed ) {
		return $title;
	}
	
	// Remove the title on our single post with the ID "10" and "20"
	// Add as many IDs as you like into the array, separated by commas
	if ( is_single( array( 10, 20 ) ) && in_the_loop() && $title == $post->post_title )
		return '';
	
	// For everything else, return the title as it should be
	return $title;
}

add_filter( 'the_content', 'generate_content_filter_completed' );
function generate_content_filter_completed( $content ) 
{
	global $generate_content_filter_completed;
	$generate_content_filter_completed = true;
	return $content;
}

Then we’ll make some CSS adjustments:

.postid-10 .entry-content,
.postid-20 .entry-content {
      margin-top: 0;
}

.postid-10 .entry-header,
.postid-20 .entry-header {
      display: none;
}

Alright, so we’ve removed the title from our two posts (10 and 20).

Now, we’ll add our title and meta for these posts into the After Header hook:

add_action('generate_after_header','generate_add_post_title_below_header');
function generate_add_post_title_below_header()
{ 
	// Add the single post IDs we want to target to the array below, separated by commas
	if ( is_single( array( 10, 20 ) ) ) : ?>
		<div class="page-header-content generate-page-header generate-content-header">
			<div class="inside-page-header-container inside-content-header grid-container grid-parent">
				<header class="entry-header">
					<?php the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' ); ?>
					<div class="entry-meta">
						<?php generate_posted_on(); ?>
					</div><!-- .entry-meta -->
				</header><!-- .entry-header -->
			</div>
		</div>
	<?php endif;
}

That’s the jist of it.

Not the easiest thing to do, but it works! πŸ™‚