Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8767507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:49:56+00:00 2026-06-13T16:49:56+00:00

I’m trying to display content based on the current WordPress page or subpage, working

  • 0

I’m trying to display content based on the current WordPress page or subpage, working with page titles instead of IDs.

What I have is this:

<?php if ( is_page( array( 'About', 'Chi Siamo' ) ) || ( get_the_title( $post->post_parent ) == ( array( 'About', 'Chi Siamo' ) ) ) ) { ?>
<p>Hello Joe</p>
<?php } else {} ?>

Not sure why, but it’s working on identifying the page names, but not the subpages of that page.

Can anyone see what I may have done wrong? Syntax error?

Thanks

PS. I have also tried

<?php if (get_the_title() || get_the_title( $post->post_parent ) == array( 'About', 'Chi Siamo' ) ) { ?>

But this returns true for all pages.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:49:57+00:00Added an answer on June 13, 2026 at 4:49 pm

    I would remove the outer parentheses from the second part of your conditional: ( get_the_title( $post->post_parent ) == ( array( 'About', 'Chi Siamo' ) ) ) and make sure $post is actually what you think it is.

    Try to var_dump($post) and see if post_parent is actually present.

    It’s ugly to check for pages by title (slug or id would really be preferable), especially when it comes to finding their ancestors. The beauty of PHP is that it is dynamic, and you wont need to be manually changing IDs with each theme install. Why not get the ID of the current page and then pass it to get_ancestors?

    Store that array in a variable, maybe $ancestors, and then $ancestors[0] will be the ID of the parent page. get_the_title of that ID, and then check if that is ‘About’ or ‘Chi Siamo’.

    Update:

    Here’s my previous answer in copyable code form:

    $ancestors = get_ancestors($post->ID);
    $parent_id = $ancestors[0]
    $parent_title = get_the_title($parent_id);
    

    and then your conditional

    if ( is_page(array('About', 'Chi Siamo' )) || $parent_title == 'About' || $parent_title == 'Chi Siamo') {
        echo '<p>Howdy</p>';
    } else {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.