Archived topic
Header Element how to replace site title and description with post title ?
5 replies · Started by Michael on January 20, 2020
Really digging the header element, and how it looks. I've searched how to replace the site title and tagline with just the post title. Can't seem to find that.
Looks really good as it is, but header looks a bit "bulky" with both there. How would I go about that.
Also, any chance of implementing a "show/hide" code button here in the forums. Lots of scrolling in lots of posts that have code pasted in them, just an idea?
Hi Michael,
The Header Element itself isn't able to replace the site title, unfortunately.
However, you can do this with a filter:
add_filter( 'generate_site_title_output', function( $output ) {
if ( ! is_singular() ) {
return $output;
}
return sprintf(
'<%1$s class="main-title" itemprop="headline">
<a href="%2$s" rel="home">
%3$s
</a>
</%1$s>',
( is_front_page() && is_home() ) ? 'h1' : 'p',
esc_url( apply_filters( 'generate_site_title_href', home_url( '/' ) ) ),
get_the_title()
);
} );
Let me know if that helps or not :)
Works well, but it is still showing the site tagline under the post title?
Try adding this as well:
add_filter( 'generate_site_description_output', function( $output ) {
if ( ! is_singular() ) {
return $output;
}
return '';
} );
Genius, and thank you Tom.
You're welcome :)