It's very specific to avoid abandoned houses qualifying, but there are allowance on case by case basis.
Below from the guidance note might help:
"Purchase of site containing a derelict house
First-time buyers may purchase a site containing a house which is derelict
and which they plan to demolish, in whole or in part, with the intention of
building a new house. First time buyers intending to undertake such
purchases should contact Revenue who will consider eligibility for HTB in
such circumstances on a case by case basis."