• Hi guys,

    Just noticed in my source code that Age Gate is throwing up duplicate H1 tags on my pages and posts.

    The duplicate tags are not really obvious, and in fact come out as blank tags, as I’m using an image heading rather than a text heading.

    The tags though are still there – would it be possible to have alternatives, H1, H2, H3, span, div tags in there so that we aren’t forced to use H1 tags?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Phil

    (@philsbury)

    Hi @steveraven,

    It shouldn’t ever spit out blank tags so if it is and you can screenshot the source that’d be good to see.

    For the elements themselves, while I don’t think the code is an issue per W3 spec, and search engines won’t be age checked it’s possible to change them to whatever you need using a filter (or two). Here’s an example:

    `
    add_filter(‘age_gate_logo’, function($markup){
    return str_replace(‘h1’, ‘div’, $markup);
    }, 10, 1);

    add_filter(‘age_gate_messaging’, function($markup){
    return str_replace(‘h2’, ‘div’, $markup);
    }, 10, 1);
    `

    Just replace the 'div' with whatever you want to use.

    Cheers
    Phil

    Thread Starter steveraven

    (@steveraven)

    Hi Phil,

    Well they’re not actually blank as such – they’ve got lots of files and an image upload in there, none of them showing tags as – well, it’s an image – but the H1 tags are still showing as blank ones, viz-a-viz:

    <h1 class="age-gate-heading age-gate-logo"><img src="https://www.midlandsmaidens.com/wp-content/uploads/2018/10/rrtestd-e1539731582819.jpg" alt="Midlands Maidens" class="age-gate-logo-image" /></h1>

    I’m not too worried about the H2 tag in the second part of the code, but I’ll certainly try adding the first piece of code into my child theme functions.php and let you know how it goes.

    Thread Starter steveraven

    (@steveraven)

    No difference whatsoever in the H1 tags count.

    When you say I can ‘change the ‘div’ to whatever I wanted’, how do I do that in the supplied code snippet?

    And also, how do I get rid of the H1 tag using the above snippet?

    • This reply was modified 5 years, 11 months ago by steveraven.
    Plugin Author Phil

    (@philsbury)

    Hmm, it should have replaced the h1 with a div like this image

    In the str_replace above we look for a string of h1 and swap it for a string of div. So changing the div text to, say, span will make the element a span.

    If you wanted to remove the whole wrapping element you could do:

    
    add_filter('age_gate_logo', function($markup){
      
      return preg_replace('/<h1 class="(.*?)">(.*?)<\/h1>/', '$2', $markup);
    
    }, 10, 1);
    

    Which should just output just the image tag. This will lose a couple of css classes though, but it should be ok.

    As ever with these things you might have to clear your cache before seeing the changes if you’re working straight in a live environment.

    Cheers
    Phil

    Thread Starter steveraven

    (@steveraven)

    Hi Phil,

    Yes, the above code snippet solved it!

    However after clearing the cache, clearing the cloudflare cache, and pressing f5 for a hard reset, the H1 tag was still appearing – so I ran Crap Cleaner to wipe the lot out.

    After this it worked fine, so it’s quite possible that the first set of snippets worked too.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Question on ‘Tags’’ is closed to new replies.