A client's WordPress site looked fine on the home page and on its product pages. Every blog post, though, had two problems: a PHP warning printed at the top, and an empty <h1>. The cause was one line in the theme's single.php.

The symptom

Open any post and you saw:

  • a PHP warning above the content about accessing an array offset on a value that wasn't an array;
  • an <h1></h1> with nothing inside it.

The empty H1 is the expensive part. Search engines and screen readers use the H1 as the page's main heading. Every article on the blog was effectively untitled.

The cause

The theme was built for its own custom post type. In single.php the title came from the theme's own data array (simplified):

<h1><?php echo $content['title']; ?></h1> 

That array is filled for the theme's own content type. On an ordinary blog post it isn't, so $content wasn't an array. PHP raised a warning for $content['title'], returned null, and the heading came out empty.

The fix

Fall back to the standard WordPress title when the theme's field isn't there:

<?php $mc_title = (is_array($content) && !empty($content['title'])) ? $content['title'] : get_the_title(); ?> <h1><?php echo esc_html($mc_title); ?></h1> 

Two checks matter. is_array() stops the warning. !empty() catches the case where the field exists but is blank, so you never print an empty heading again. esc_html() is worth adding while you are there.

Do it in a child theme

Editing the parent theme works until the next theme update overwrites it. Copy single.php into a child theme and change it there. On this site we patched the parent theme directly, so the change is written down and gets re-checked after every theme update.

Check the rest of the site

After the fix, look for the same pattern elsewhere:

  1. Search the theme for $content[' and similar direct array reads from meta.
  2. Open one page of every template type (post, page, archive, custom type) and check for exactly one non-empty H1.
  3. Turn WP_DEBUG_DISPLAY off on production so warnings go to the log, not to visitors.

Takeaway

A theme that assumes its own data structure will break quietly the moment the site is used in a way the theme author didn't plan for. Guard every read from post meta, and always fall back to the WordPress core value.

I build and maintain small-business websites at Weblevo.