Estimated Reading Time: 2 min
To change the title of your WordPress front page from an <h2>
to an <h4>
tag using a function, you can use the the_title
filter hook in your theme’s functions.php
file. Here’s how you can do it:
- Open your theme’s
functions.php
file: You can access this file via the WordPress admin dashboard under Appearance > Theme Editor, or via FTP/SFTP. - Add the following code to
functions.php
:
function change_front_page_title_tag( $title, $id = null ) {
// Check if it's the front page
if ( is_front_page() ) {
// Wrap the title in an <h4> tag
$title = '<h4>' . $title . '</h4>';
}
return $title;
}
add_filter( 'the_title', 'change_front_page_title_tag', 10, 2 );
Explanation:
is_front_page()
: This conditional tag checks if the current page is the front page.the_title
filter: This filter allows you to modify the title output.$title
: The original title of the post or page.$id
: The ID of the post or page (optional).

What This Does:
- The function checks if the current page is the front page using
is_front_page()
. - If it is the front page, it wraps the title in an
<h4>
tag. - The modified title is then returned.
- Save the changes: After adding the code, save the
functions.php
file.
Notes:
- Ensure your theme uses
the_title()
to display the title. If your theme uses a custom function or hardcoded HTML, this filter may not work. - If you’re using a caching plugin, clear the cache to see the changes immediately.
Let me know if you need further assistance!