0

So to increase my SEO score I require all tag pages to have a H1 title, for example website.com/tags/taghere would need the title: <h1>TagHere</h1> or simply <h1>taghere</h1>

I can go through each tag manually and add them but this would beyond tiresome to do for 1000+ tags, we're running the Avada theme and I can't see any option anywhere to do this automatically.

Is there a way I can create a function for the functions.php to do it automatically?

Essentially I want to do the same as what you see:

Hopefully someone can advise a solution, this would then also be usable for categories too.

enter image description here

  • Guess you can output hidden h1 tag on tag page template, instead of typing it for every tag manually. – anton May 2 at 12:30
  • The only php files under my child theme are "functions.php", "header.php", "footer.php" and under "template" folder there is another "header.php" – Ryflex May 2 at 12:46
  • Can this hidden h1 tag with term name be pasted just after open body tag ? – anton May 2 at 13:03
  • @anton I don't see why not, it's hidden so it'll do nothing visually... – Ryflex May 2 at 13:27
  • Keep in mind most search engines can tell when something is hidden, so it's doubtful that adding hidden H1s will have any impact on your actual rankings - even if whatever you're using to "grade" each page gives you a nice green checkmark because technically there is one in the HTML. – WebElaine May 2 at 13:40
0
  1. Create custom action in function.php, which checks current page type (if it's category or tag page).

    function hidden_term_name_action() {
    
        if( is_category() || is_tag() ){
    
            $term_id = get_queried_object_id();
            $term = get_term($term_id);
            if($term){
                echo sprintf('<h1 style="display:none;">%s</h1>', esc_attr($term->name));
            }
        }
    
    }
    
    add_action('hidden_term_name', 'hidden_term_name_action');
    
  2. Paste this code in header.php, which fires this action and pastes term title inside hidden h1 tag.

    <?php do_action('hidden_term_name'); ?>
    

P.S. Not tested, but give it a try.

  • Hmm, it doesn't appear to do anything. No errors, nothing. – Ryflex May 2 at 20:00
  • Did you inspect page's source code? To check if this custom action works, you may add else to if statement and echo something to check if get_term returns something or not. On my localhost it works well. – anton May 2 at 20:07
  • You're missing a bracket are you not? } is missing. I just checked my theme and it shows unexpected end of file – Ryflex May 6 at 23:45
  • yeap, first if statement is not closed – anton May 7 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.