Check if page parent has certain template

I want to check if a page has a parent with a certain page template attached to it.

If I know that I can determine which scripts to load or not.
Normally I would just get the page template and if it is a match load the scripts needed but now I have the script in my functions.php file and can’t get the $page->ID to check.

I don’t really know how to solve this.
In my functions.php:

require_once('js/my_script.php');  

my_script.php:

add_filter( 'admin_post_thumbnail_html', 'function_name');
function functions_name( $myhtml ) {
    //do stuff
};

This hooks into an existing function. I can’t check within the function because that would disable the complete function if the statement would be false.

1 Answer
1

This question has been answered on Stack Overflow before:
https://stackoverflow.com/a/14626254/844732

add_action( 'admin_head', 'check_page_template' );
function check_page_template() {
    global $post;
    if ( 'page-homepage.php' == get_post_meta( $post->ID, '_wp_page_template', true ) ) {
        // The current page has the foobar template assigned
        // do something

    }
}

Leave a Comment