I ran your filter in my development area. It didn't work. Then I switched off the Yoast SEO plugin, which I knew was also messing with the page title. Then it worked. So my suggestion would be it is another plugin that is messing with it.
In the case of Yoast, it was a filter call to pre_get_document_title
that returnedreturning non empty. In that case wp_get_document_title
is short circuited anand the rest of the function, including the documents_title_parts
filter, is not evaluated, as you can see from the first lines of code:
$title = apply_filters( 'pre_get_document_title', '' );
if ( ! empty( $title ) ) {
return $title;
}
So, I took your filter and changed the hook to pre_get_document_title
. It didn't work. Then I changed the priority to a higher level than the same filter in Yoast. Then it worked. So, I don't know about your set-up, but I suggest you give this a try:
add_filter( 'pre_get_document_title', function( $title )
{
error_log('here');
return $title;
}, 999, 1 );