Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Attempt to read property "post_parent" on null #11

Open
rickhellewell opened this issue Mar 27, 2024 · 1 comment
Open

Error: Attempt to read property "post_parent" on null #11

rickhellewell opened this issue Mar 27, 2024 · 1 comment
Labels
question Further information is requested

Comments

@rickhellewell
Copy link

Noticing this error on a WP install (fully updated) with latest Pages theme:

PHP Warning: Attempt to read property "post_parent" on null in <path-to-root>/wp-content/themes/pages/functions.php on line 163

@bhadaway bhadaway added the question Further information is requested label Mar 27, 2024
@bhadaway
Copy link
Owner

I don't see the warning (probably because we're on different versions of PHP), but I do believe I fixed it.

Before I push the update live for everyone are you comfortable testing the fix to see if it clears all warnings?

If so, update lines 160-165 of functions.php to:

if ( isset( $post->post_parent ) ? $post->post_parent : 0 ) {
echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="' . esc_url( get_permalink( $post->post_parent ) ) . '" itemprop="item"><span itemprop="name">' . esc_attr( get_the_title( $post->post_parent ) ) . '</span></a><meta itemprop="position" content="2" /></li>';
}
if ( is_single() || !empty( $post->post_parent ) ) {
echo ' <span aria-hidden="true">&rarr;</span> ';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants