Working on my first Wordpress site so I'm sure this is a really basic question. I'm struggling to write a conditional php statement that performs a certain action when a page is a child of a parent page.
For example, rather than just specifying one page, as below, I'd like to specify all pages that have the 'About Us' page as a parent:
<?php if (is_page('About Us')) echo 'Hello World!'; ?>
I've tried the "child_of" function but it wasn't as straightforward as I'd hoped.
When I use the below, I get a syntax error - probably just me not knowing how to use the function:
<?php if (child_of('About Us')) echo 'Hello World!'; ?>
You're getting an error because there is no such thing as a
child_of() function in WordPress.
child_of() is a way of searching using the get_pages() function.
$pages = get_pages('child_of=##');
where ## is the numeric ID (not the name) of the 'About us' page.