Enqueue script only on child pages of custom post types

I want to enqueue a script on the child pages of two different custom post types. The custom post types are named “Foods” with post id of 10000, and the other is named “Drinks” with a post ID of 20000. The child pages have a slug of /food/ and /drink/ while the parents have the slug /foods/ and /drinks/.

The code I have in my functions.php file is the following, but it is showing the script on all pages instead of just the child pages of the custom post types. What am I doing incorrectly?

function addScript() {
global $post;

if ($post->post_parent_in(array(‘10000′,’20000’))) {
wp_enqueue_script(‘script.js’);
}
}

addScript();

Read more here:: Enqueue script only on child pages of custom post types

Leave a Reply

Your email address will not be published. Required fields are marked *