Attempt to read property on null Error in WordPress

Hello WordPress community!

If you’ve been grappling with the frustrating “Attempt to read property on null” error, you’re not alone. This post will guide you through understanding and resolving this common yet perplexing issue.

Before we dive in, I’d like to ask a small favour:

If you find this post helpful, please consider following me on LinkedIn. Your support encourages me to continue sharing technical insights with the community!

https://www.linkedin.com/in/benoitrivaux/

The Problem:

Many WordPress users encounter errors similar to these:

Additionally, some users may see a PHP SESSION critical error in their site health check:

  • Warning: Attempt to read property "post_status" on null in public_html/wp-admin/includes/template.php on line 2204
  • Warning: Attempt to read property "ID" on null in /public_html/wp-admin/includes/template.php on line 2208
A PHP session was created by a session_start() function call. 
This interferes with REST API and loopback requests. 
The session should be closed by session_write_close() before making any HTTP requests.

These errors often occur when accessing the WordPress customisation page or other theme-related areas.

The Root Cause

After extensive investigation and beating myself 10 times against the wall, I’ve identified a common scenario leading to these errors:

This combination can result in “ghost” menu items, causing crashes particularly around the header area, which explains the session-related critical error.

The Solution

The key to resolving this issue lies in thoroughly examining and cleaning up your WordPress menus.

Here’s a step-by-step guide:

Go to this page:
/wp-admin/nav-menus.php

And check all your menus(even the ones you do not use or are part of your footer):

Warning: Attempt to read property

Warning: Attempt to read property

Why This Works

By removing references to deleted pages from all menus, including those you might not actively use or be aware of, you eliminate the source of the null property errors. The cache clearing ensures that these changes are immediately reflected across your site.

Conclusion

While this issue can be incredibly frustrating, the solution is often simpler than it appears. By methodically checking your menus and removing invalid links, you can resolve these errors and get your WordPress site back on track.

Remember, WordPress is a complex ecosystem, and sometimes the most elusive bugs have the simplest solutions. Always approach troubleshooting systematically, and don’t hesitate to dig into areas of your site you might not frequently visit.

If this post has helped you resolve your WordPress woes, I’d be incredibly grateful if you could follow me on LinkedIn. Your support motivates me to continue sharing technical insights and solutions with the WordPress community.

FOLLOW-ME-LINKEDIN

Happy WordPress-ing!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Disclaimer:

As an Amazon Associate I earn from qualifying purchases. This post may contain affiliate links which means I may receive a commission for purchases made through links.