"Were" used this way is called the subjunctive mood. This mood is used to express a wish or possible situation that is currently not true. It's usually used with words like "if" and "wish".
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.