SEO PHP Beginner

Change the Page Title Separator and Format

Change the dash between the page and site name in browser tabs and search results, and drop the tagline from the homepage title.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 8 lines
// "Page title | Site name" instead of "Page title – Site name".
add_filter( 'document_title_separator', fn () => '|' );

// Remove the tagline from the homepage title.
add_filter( 'document_title_parts', function ( array $parts ): array {
	unset( $parts['tagline'] );
	return $parts;
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Don't use with Yoast SEO, Rank Math, Slim SEO, SEOPress, All in One SEO. Check the notes below before adding it.

WordPress builds each page’s &lt;title&gt; as “Page – Site” and adds the tagline on the homepage. These two filters let you change the separator and choose which parts appear.

How it works

document_title_separator sets the character between parts. document_title_parts receives the parts as an array with keys title, page (for paginated pages), tagline and site. Removing the tagline gives a shorter homepage title.

Things to watch

  • This only works if your theme lets WordPress manage the title with add_theme_support( 'title-tag' ), which nearly all themes do.
  • SEO plugins replace these titles entirely. Use their title settings instead.

How to test it

Check your browser tab on a post. It should read “Post title | Site name”.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only