Jump to content

Removing an H1 wrapper from my header

Recommended Posts

Hey Y'all!

I'm a one person marketing team for my company and we work with a third party seo agency for keeping our site inline with SEO best practices. In our latest audit, we found an h1 tag wrapped around our site img logo. This has two negative consequences: First, the H1 is not visible to users which can be considered black hat SEO and a negative rank factor for your site. Secondly, Google and other search engines are reading this same H1 as the primary header for each page because it comes before all other H tag indicators. 

<h1 id="logoImage"><a href="/"><img alt="Hybrid Cloud Management Platform | Cloud Management Platform | RackWare" data-src="https://www.rackwareinc.com/.hb-image/Lyo-/UG02YWM1NStIVWhFRXJMdXVhOFNVSXVWQkhoRTdSSU0-" class=" hb-defer-offscreen" /></a></h1>

I tried plugging in some custom code in the code injector to remove the h1 wrapper, but nothing seems to be working. As I'm not a web developer, wanted to reach out to the forum and see if there were any suggestions or recommendations. I'll attach what I tried throwing into the custom code injector below: 

<script> 
document.addEventListener('DOMContentLoaded', function() {
    // Get the h1 element
    var h1Element = document.getElementById('logoImage');

    if (h1Element) {
        // Create a new anchor element
        var anchorElement = document.createElement('a');

        // Get the img element within the h1
        var imgElement = h1Element.querySelector('img');

        // Set attributes of the anchor element
        anchorElement.setAttribute('href', '/');
        anchorElement.appendChild(imgElement.cloneNode(true)); // Cloning the img element

        // Replace the h1 element with the anchor element
        h1Element.parentNode.replaceChild(anchorElement, h1Element);
    }
});
</script>

Thanks!

Link to comment
  • Replies 1
  • Views 387
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Please post the URL for a page on your site where we can see your issue. For us to see the URL you need to include the link in the content of your post. The URL field the forum software provides is not shown to us.

A link to the backend of the your site won’t work for us, i.e. a URL that contains /config/.

Please set up a site-wide password, if your site is not public and you've not already done so.

Post the password here.

Adding a site-wide password does not allow anyone to alter your site. It only allows those with the password to see your site.

Please read the site-wide password and how to share a link documentation to understand how they work.

You may find How to post a forum question post useful.

We can then take a look at your issue.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.