[Resolved] H1 for homepage logo

Home Forums Support [Resolved] H1 for homepage logo

Home Forums Support H1 for homepage logo

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #1161967
    johnaps

    Hello, i have read all other support threads about this matter and non of the solutions written were of any help to my site…

    I am trying to make my logo which is right next to the hamburger button, an h1 tag for seo purposes…
    Its important though to not mess with any spacing of any element in any media, because everything is preconfigured and with no available space…

    Fore example i tried implementing 2 hooks one before site logo and one after with the first containing <h1> and the second </h1> respectively but no matter what css i tried my header spacings were messed up.

    I think maybe with php code i ll be able to solve this, so if you can forward this directly to Tom, it would be very much appreciated!

    But any suggestions are welcomed of course!~

    #1161994
    David
    Staff
    Customer Support

    Hi there,

    you can try this PHP snippet to add the H1 for the homepage only:

    <?php
    add_filter( 'generate_logo_output', 'db_home_logo_htag', 10, 3 );
    function db_home_logo_htag( $output, $logo_url, $html_attr ) {
    
        if ( is_front_page() ) {
        
            printf(
    		'<div class="site-logo">
                <h1>
    			    <a href="%1$s" title="%2$s" rel="home">
    				    <img %3$s />
                    </a>
                </h1>
    		</div>',
    		esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ),
    		esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
    		$html_attr
        
            );
        } else {
        
            printf(
    		'<div class="site-logo">
    		    <a href="%1$s" title="%2$s" rel="home">
    			    <img %3$s />
    			</a>
    		</div>',
    		esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ),
    		esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
    		$html_attr
        
            );
        }
    
    }

    Then this CSS to remove the H1 styling:

    .site-logo h1 {
        margin-bottom: 0 !important;
        line-height: unset;
        font-size: 0;
    }
    #1162081
    johnaps

    thank you very much! It worked! Is there any place in the code that i can manipulate whats my h1 “data” will be? Because i see in the code

    a href=”%1$s” title=”%2$s” rel=”home”

    or is that my logo’s div?

    Thank you very much!

    #1162186
    David
    Staff
    Customer Support

    What do you want it to be?

    #1165906
    johnaps

    Ι guess my site’s name with the city my physical store is in, which also contains the main keyword for my niche…
    something like “Σοφιανός Ορθοπεδικά Είδη Αθήνα”

    #1166040
    David
    Staff
    Customer Support

    I mean the HTML 🙂

    So in the code you will see this:

    <h1>
        <a href="%1$s" title="%2$s" rel="home">
            <img %3$s />
        </a>
    </h1>

    You can edit the HTML to include any attributes you need eg.

    <h1 title="my site title">
        <a href="%1$s" title="%2$s" rel="home">
            <img %3$s />
        </a>
    </h1>
    #1166125
    johnaps

    so i can change the attribute title to title=“Σοφιανός Ορθοπεδικά Είδη Αθήνα”?

    #1166252
    David
    Staff
    Customer Support

    Thats correct

    #1860296
    CavalierPip

    This solution breaks the REST API. I cannot search for plugins via the WP interface and some of the plugins (eg. Media Cleaner) throws an error after implementing this.

    View post on imgur.com

    The minute I remove the solution, everything works. I have tried it multiple times to verify this.

    #1860667
    David
    Staff
    Customer Support

    Hi there,

    that snippet is specific to filter hooks in the GP Theme. The code only fires when that filter is reached in the GP template. It should not affect any other code especially on the backend.

    Its more likely whatever the Media Cleaner plugin is doing to images that has caused the breakage.

    So i had a search for that specific error and this was the top of the Google search results:

    https://wordpress.org/support/topic/rest-api-is-disabled-or-broken-2/

    I would ask the plugin author if he can take a look at the code as he may have some input on if the plugin would interfere with that.

    #1860735
    CavalierPip

    It is not just that plugin. I disabled Media Cleaner (and other similar plugins I installed after implementing this solution). Now, as I said in the above post, I cannot search for plugins. It just keeps searching with no result. When I disable the solution, I get plugin search results immediately.

    View post on imgur.com

    #1860743
    David
    Staff
    Customer Support

    Can i suggest you raise a new topic – so we can help debug the issue with you. This will stop the OP from receiving unrequired notifications.

    #2321109
    Ted

    Greetings,
    I am trying to implement this snippet on my site. It’s not working because I don’t use a logo, just text as the logo. Could you suggest the code for this?

    Many thanks

    #2321196
    David
    Staff
    Customer Support

    Hi there,

    if you’re only displaying the Site Title and your home page is set to Display the Latest Posts then GP will automatically output the H1.

    Are you using a static homepage ? Could i see the site ?

    #2321505
    Ted

    greetings thanks for your reply,

    yes it’s a static homepage. https://thegreatestsong.com. Not sure what to do.

Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.