create child page emplate dynamically in wordpress

Mixing some functions from here and here I wrote the code below in my functions.php: Now, every time a child page is created or updated it will have as page template a file named “page-parentslug-child.php. for example: ‘PARENT’ => page-slug.php (default) ‘parent’> ‘CHILD’ => page-‘PARENTSLUG’-child.php ‘parent’> ‘child’> ‘GRANDCHILD’ => page-‘CHILDSLUG’-child.php ‘parent’> ‘child’> ‘grandchild’ > ‘GRAND-GRANDCHILD’ […]