Want to add the H1 tag to website logo in the Astra theme for SEO reasons? While inner pages have their page title as H1 tag, you may want to wrap logo with H1 tag for homepage only when using Astra theme. This can be achieved via custom code.
Code Snippet: Add H1 tag to Homepage Logo
In the WordPress Dashboard, go to Appearance > Theme Editor and open the functions.php file of your Astra child theme. Then add the following code at the end. Alternatively, you can use code snippets plugin for adding custom code.
1 2 3 4 5 6 7 8 9 |
add_filter( 'astra_logo', 'wpd_astra_logo_wrap_h1' ); function wpd_astra_logo_wrap_h1( $html ) { if( has_custom_logo() && ( is_home() || is_front_page() ) ) { $html = str_replace( '<span ', '<h1 ', $html ); $html = str_replace( '</span>', '</h1>', $html ); } return $html; } |
Praveen says
Hello Paul. Appreciate your work. But when I deployed the code, I see two blank H1 tags on homepage. Can you verify at your end?
Việt Anh Trần says
Thank you from Viet Nam