$query->is_home()
is not, well, ‘home’. $query->is_home()
checks of you are viewing the blog/posts page. It’s an artifact from when the home page of WordPress sites was invariably the blog. You want to change that to $query->is_front_page()
, which checks if the front page of the website is a page, and if you are on that page.