Warning: Attempt to read property “ID” on null in D:\xampp\htdocs\yba\wp-content\themes\young-brand-child\functions.php on line 162 [closed]

I’m guessing the problem is here:

$pg_name = apply_filters( 'the_title', $item->title, $item->ID );
$page_id = get_page_by_title( $pg_name );
$item_output .= '<a'. $attributes .' id="'.$page_id->ID.'">';

I don’t think this makes any sense:

  • you have the item title and ID
  • you’re filtering the title
  • and then you’re trying to look up the page ID again by the new, modified title? Which in this case doesn’t exist.

I’d replace these three lines with just

$item_output .= '<a'. $attributes .' id="'. $item->ID .'">';

Unless you’re trying to do something specific here I’m not seeing?

If you do want to compute $pg_name like this then you can reuse it in the $item_output .= line just after the comment that runs the same filter again.