Modify WordPress Page Title ()

It’s important to read the documentation for filters. The documentation for pre_get_document_title says (emphasis mine):

Filters the document title before it is generated.

and

$title
(string) The document title. Default empty string.

So when using pre_get_document_title, the title has not been set yet, so when you do this:

return $title . ' new title';

$title is — as documented — an empty string, so the result will be:

' new title'

So if you want to modify the existing title, you need to use document_title_parts, where you’ll modify $title['title']:

add_filter(
    'document_title_parts',
    function( $title ) {
        $title['title'] = substr( $title['title'], 4 ); // This needs to be 4, to account for the space.

        return $title;
    }
);