How to hide page titles in WordPress without plugin

Posted on

To hide page titles in WordPress without using a plugin, you can employ custom CSS or make modifications directly to your theme files. First, navigate to your WordPress dashboard and go to "Appearance" > "Customize". Depending on your theme, you may find a "Additional CSS" or similar option where you can add custom CSS code. To hide page titles using CSS, you can use the following code snippet:

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

This CSS code targets pages specifically (.page) and hides the .entry-header element, which typically contains the page title. After adding the code, make sure to click "Publish" or "Save & Publish" to apply the changes. If your theme does not have a built-in custom CSS option, you can edit your theme’s stylesheet directly. Access your WordPress files via FTP or file manager, navigate to wp-content/themes/your-theme/style.css, and add the same CSS snippet at the end of the file. Remember to save the changes, and your page titles should now be hidden across your WordPress site.

Using Child Theme Modifications

For more advanced users or those concerned about theme updates overriding their changes, creating a child theme is recommended. Start by creating a child theme directory within wp-content/themes/, then create a style.css file within this directory. In the style.css file, enqueue the parent theme’s stylesheet and add your custom CSS code to hide page titles. This method ensures that your modifications are preserved when the parent theme updates, providing a sustainable solution for customizing your WordPress site without relying on plugins.

Editing Theme Template Files

Alternatively, you can directly modify your theme’s template files to hide page titles. Locate the appropriate template file (page.php, single.php, etc.) within your theme directory (wp-content/themes/your-theme/). Open the file using a text editor or through the WordPress theme editor, and find the section where the page title is outputted, typically within the header or entry-header section. You can comment out or delete the code responsible for displaying the title. For example, in page.php, you might look for the_title() or similar functions and remove or comment them out using PHP comment tags (/* */). Save the changes, and refresh your WordPress site to see the page titles hidden.

Conditional Tags for Specific Pages

If you want to hide titles on specific pages rather than all pages, you can use WordPress conditional tags within your theme’s template files. For example, to hide the title on a page with ID 123, you can modify your template file as follows:

<?php
if ( ! is_page( 123 ) ) {
    get_header();
}
?>

Replace 123 with the ID of your specific page and adjust the logic as needed to exclude displaying the title conditionally. This approach allows for granular control over which pages display titles based on predefined conditions using WordPress conditional tags.

Implementing Hooks and Filters

For developers familiar with WordPress hooks and filters, you can utilize them to hide page titles programmatically without directly modifying template files. Hooks such as the_title or get_the_title can be targeted with custom functions added to your theme’s functions.php file or a custom plugin. For instance, you can use the following code snippet to modify the output of page titles:

<?php
add_filter( 'the_title', 'hide_page_title' );
function hide_page_title( $title ) {
    if ( is_page() ) { // Modify condition as needed
        return ''; // Replace with any custom output or leave empty to hide
    }
    return $title;
}
?>

This example filters the page title output using the_title filter and returns an empty string for pages, effectively hiding the title. Adjust the condition and return value according to your specific requirements to achieve the desired functionality. Remember to save changes and test thoroughly to ensure compatibility with your WordPress theme and plugins.

By leveraging these methods—custom CSS, child theme modifications, template file edits, conditional tags, and hooks—you can effectively hide page titles in WordPress without relying on plugins, tailoring the solution to suit your customization needs and ensuring your site maintains functionality and visual coherence across various devices and browsers.