(a) The recording of a homestead declaration (as defined in Section 704.910) does not limit or affect the right of a plaintiff to attach the declared homestead described in the homestead declaration, whether the homestead declaration is recorded before or after the declared homestead is attached.
(b) An attachment lien attaches to a homestead (as defined in Section 704.710) in the amount of any surplus over the total of the following:
(1) All liens and encumbrances on the homestead at the time the attachment lien is created.
(2) The homestead exemption set forth in Section 704.730.
(c) Nothing in subdivision (a) or (b) limits the right of the defendant to an exemption under subdivision (b) of Section 487.020.
(d) Notwithstanding subdivision (b), a homestead (as defined in Section 704.710) is exempt from sale to the extent provided in Section 704.800 when it is sought to be sold to enforce the judgment obtained in the action in which the attachment was obtained.