check if current page is a child of a specified top level page

I won’t give a solution to your actual issue but I will show you how you can verify if current page is child of a specific top level page. If you need to check the current page has specific Parent page the you can do like this:

<?php
    $currentPage = get_the_id();
    $pageAncestors = get_post_ancestors($currentPage);

    $hasParent = in_array($currentPage,$pageAncestors);

here get_post_ancestors will return all parent id of that specific page as array and using in_array you can validate if id exists. Read more about get_post_ancestors here.