带有页面加载脚本的PHP动态Pagetitle

Good Evening!

I ran into a little problem with my current website project.
So i wanted to have dynamic page titles and maybe descriptions.
I tried doing it with a seperate header file and including it then through PHP.

The Problem is, i'm using a pageload script, so that my content of the homepage for example is stored in: pages/home.php and gets then included into the index.php of my website.

I could add some php variables to my home.php but it won't be included into the header where i already defined the destination of the variable of course.

I assume that loading the home.php where the variables are saved in, after the index.php just won't recognize it.
------------------------------------------------------------------

My index.php with pageloading script:
https://gist.github.com/loohney/17f1406a7e5662b68448106cc13ce72c

My home.php:
https://gist.github.com/loohney/3ee7425b75a2bee5dc2756ed858a9d62

I hope someone can help me out with this.
Maybe there is even a better way to do this.

Every kind of help and tips are much appreciated!
Thank you!