I do not understand where exactly to place the check.

The "else" statement means that the specific key has no metadata. If this field is the title, the replace the empty string with the "Undefined" one.