How to Change the Page Title on the Browser Tab

Overview

Would you like to change the page title of the browser tab? This is very easy to do with a small snippet of code. We’ll show you the PHP needed to change this title.

Setup

By default, when viewing any page, the page title that displays in the browser tab is pulled from page or post title. This is also true when using the Conversational Forms addon or the Form Pages addon, the title that appears is the title of the form you have defined in your form settings.

In some cases, you may wish to make the browser tab title different to the actual name that displays when you load the form. To change this title, copy this code snippet to your site.

/**
 * Change the page title on the browser tab.
 * 
 * @link https://wpforms.com/developers/how-to-change-the-page-title-on-the-browser-tab/
 *
 */

function generate_custom_title( $title ) {

        // Enter the ID number of the page you want to change here
	if ( is_single( '850' ) ) {
		$title = __( 'My Custom Title', 'textdomain' );
	}
	
	return $title;  
}
add_filter( 'pre_get_document_title', 'generate_custom_title', 10, 1 );

In the code shown above, the page ID we’re targeting is 850. You’ll need to change this ID number to match your page ID. To find out this number, please check out this helpful documentation.

When using this snippet for the Conversational or Form Pages addon, the ID number you’ll need to enter in the snippet is the form ID. to find your form ID, please check out this tutorial.

And that’s it! You’ve successfully changed the title of the browser tab shown on Conversational Forms. Would you like to also change the required field indicator on WPForms? Check out our tutorial on How to Change Required Field Indicator.

Filter Reference: pre_get_document_title