The display_header_text() WordPress PHP function is used to determine if the header text should be displayed on the website or not.
Usage
if ( display_header_text() ) { // Code to display the header text goes here. }
This snippet checks if the header text is set to be displayed. If it is, the code inside the if statement will run.
Parameters
- This function does not have any parameters.
More Information
See WordPress Developer Resources: display_header_text()
This function is part of the WordPress core and was introduced in version 3.4.0.
Examples
Display Header Text
In this example, we check if the header text should be displayed. If it is, we output a custom header.
if ( display_header_text() ) { echo '<h1>Welcome to My Website!</h1>'; }
Show Custom Site Title
Here, we check if the header text is to be displayed. If yes, we display the site’s name as the title.
if ( display_header_text() ) { echo '<h1>' . get_bloginfo( 'name' ) . '</h1>'; }
Display Custom Header with Site Description
In this case, we’re checking if the header text should be displayed, and if so, we output the site’s name and description.
if ( display_header_text() ) { echo '<h1>' . get_bloginfo( 'name' ) . '</h1>'; echo '<p>' . get_bloginfo( 'description' ) . '</p>'; }
Conditional Header Text
In this example, we show different header text based on whether the header text is set to be displayed or not.
if ( display_header_text() ) { echo '<h1>Welcome Back!</h1>'; } else { echo '<h1>Welcome!</h1>'; }
Display Header Text Only on Homepage
In this final example, we display the header text only on the homepage of the site.
if ( is_front_page() && display_header_text() ) { echo '<h1>Welcome to the Homepage!</h1>'; }