Adding a H1 Tag to Post Tags automatically, but hide the tag? (Same for Category)

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: h1TagHere/h1 or simply h1taghere/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.

Topic plugin-wp-seo-yoast tags categories seo Wordpress

Category Web


  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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.