Only display notification on single post

I think the solution is to check if it’s the main query. WordPress has a function for that, is_main_query()

The query that you’re running in your related posts widget is a secondary query, so is_main_query() will return false.

You can take advantage of that, by changing your code like this:

if ( ! is_main_query() || ! is_singular() )
return $content;