Replace SEO title tag with dynamically generated value

Try the use clause:

add_filter( 'pre_get_document_title', function ( $title ) use ( $custom_document_title ) {
    ...
} );

You can remove the global $custom_document_title; line with use.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)