[Resolved] Header Element how to replace site title and description with post title ?

Home Forums Support Header Element how to replace site title and description with post title ?

  • This topic has 5 replies, 2 voices, and was last updated 1 year ago by Tom.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1138339
    Michael

    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?

    #1138545
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #1138808
    Michael

    Works well, but it is still showing the site tagline under the post title?

    #1139324
    Tom
    Lead Developer
    Lead Developer

    Try adding this as well:

    add_filter( 'generate_site_description_output', function( $output ) {
        if ( ! is_singular() ) {
            return $output;
        }
    
        return '';
    } );
    #1139544
    Michael

    Genius, and thank you Tom.

    #1139723
    Tom
    Lead Developer
    Lead Developer
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.