Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

FIlter to change category title to h2

  • Is there a filter I can use in function to set the category title to h2? I like to set my h1 separated using the description on the category to put in an h1 and text, but the output of the category title as an h1 is throwing that off.

    Thanks

  • Hi there,

    Do you mean the category title on the category archive page?

    The easiest option is to create a block element – page hero for the category archives.

    Then you can define the category title as h2.
    https://www.screencast.com/t/Hxyiu55r3c

    Here’s a screenshot for the H2 title configuration:
    https://www.screencast.com/t/kkjicoqA3

    Here’s a screenshot for the description configuration:
    https://www.screencast.com/t/5r6mbDccP

    Let me know if this helps!

  • Hi Ying, I appeciate the help. I actually don’t like using the blocks elements, so I just wanted to know where I can switch the category title on the category page to an h2 from an h1. Can this be done with a php filter?

  • There isn’t an easy filter for this, here’s the functions you will need to change it from h1 to h2:

    function remove_generate_archive_title() {
        remove_action( 'generate_archive_title', 'generate_archive_title', 10 );
    }
    add_action( 'after_setup_theme', 'remove_generate_archive_title' );
    
    function h2_archive_title() {
        ?>
        <header <?php generate_do_attr( 'page-header' ); ?>>
            <?php
            /**
             * generate_before_archive_title hook.
             *
             * @since 0.1
             */
            do_action( 'generate_before_archive_title' );
            ?>
    
            <h2 class="page-title">
                <?php the_archive_title(); ?>
            </h2>
    
            <?php
            /**
             * generate_after_archive_title hook.
             *
             * @since 0.1
             *
             * @hooked generate_do_archive_description - 10
             */
            do_action( 'generate_after_archive_title' );
            ?>
        </header>
        <?php
    }
    add_action( 'generate_archive_title', 'h2_archive_title', 10 );
    
  • ok thanks, I thought it would be simple but I will give this a try. Thanks again.

  • worked thanks

  • No Problem 🙂

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