Last updated on September 13, 2023

Hide Page Title

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Hide the page title.

Sometimes, you may want to hide the title of a page in WordPress. This can be useful if you have a landing page or a custom page template that doesn’t require a title. Here’s how you can achieve this functionality. One way to hide the page title is by using CSS:

.page-template-template-name .entry-title {
    display: none;
}

Replace “template-name” with the name of your custom page template. This code will hide the page title on any page that uses that template.

Another way to hide the page title is by using a filter in your theme’s functions.php file. You can add the following code:

function wpsnippets_hide_page_title($title) {
    if ( is_page() ) {
        $title = '';
    }

    return $title;
}

add_filter('the_title', 'wpsnippets_hide_page_title');

This code will remove the title from any page on your site. If you only want to remove the title from certain pages, you can modify the if statement to check for specific page IDs or slugs.

Note that hiding the page title may affect your site’s SEO, as the title is an important factor in search engine rankings. Use this functionality with caution and only when necessary.

Examples

Example #1: Hide Page Title on Specific Page

This code example shows how to hide the page title on a specific page using the the_title filter hook.

function wpsnippets_hide_page_title() {
    if ( is_page( 'about' ) ) {
        return '';
    }
}

add_filter( 'the_title', 'wpsnippets_hide_page_title' );

This code checks if the current page is the “about” page and if it is, it returns an empty string, effectively hiding the page title.

Example #2: Hide Page Title on All Pages

This code example shows how to hide the page title on all pages using CSS.

.page .entry-title {
    display: none;
}

This code targets the .entry-title class on all pages and sets its display property to none, effectively hiding the page title.

Example #3: Hide Page Title on All Pages Except Homepage

This code example shows how to hide the page title on all pages except the homepage using the the_title filter hook.

function wpsnippets_hide_page_title( $title ) {
    if ( ! is_front_page() ) {
        return '';
    }
    return $title;
}

add_filter( 'the_title', 'wpsnippets_hide_page_title' );

This code checks if the current page is not the homepage and if it is not, it returns an empty string, effectively hiding the page title. If it is the homepage, it returns the original title.

Last updated on September 13, 2023. Originally posted on May 27, 2023.

Leave a Reply

Your email address will not be published. Required fields are marked *