Here's one way to obtain a cycle class, at least over a field $k$ of characteristic 0 where resolutions of singularities are available:

Let $Z \subset X$ be a subvariety of codimension $c$ (possibly singular), and let $\pi: \tilde{Z} \to Z$ be a resolution of singularities. This means $\pi$ is proper and birational, and $\tilde{Z}$ is smooth. Let $f = \iota \circ \pi : \tilde{Z} \to X$ where $\iota: Z \to X$ is the inclusion.

The (dual of the) differential $d f^\vee: f^*\Omega_X^* \to \Omega_{\tilde{Z}}^*$ induces homomorphisms of Hodge cohomology groups
$$
f^*: H^q(X, \Omega_X^p) \to H^q(\tilde{Z}, \Omega_{\tilde{Z}}^p) \text{ for all } p, q
$$
Now, $H^{\dim \tilde{Z}}(\tilde{Z}, \Omega_\tilde{Z}^{\dim \tilde{Z}}) \xrightarrow{\mathrm{Tr}, \simeq} k$ via the trace map, and the composition
$$
H^{\dim \tilde{Z}}(X, \Omega_X^{\dim \tilde{Z}}) \xrightarrow{f^*} H^{\dim \tilde{Z}}(\tilde{Z}, \Omega_{\tilde{Z}}^{\dim \tilde{Z}}) \xrightarrow{\mathrm{Tr}, \simeq} k
$$
is an element of
$$
H^{\dim \tilde{Z}}(X, \Omega_X^{\dim \tilde{Z}})^{\vee} \simeq H^{\dim X -\dim \tilde{Z}}(X, \Omega_X^{\dim X -\dim \tilde{Z}})
$$
This isomorphism comes from Poincare duality -- since $\Omega_X^{\dim \tilde{Z}} \otimes \Omega_X^{\dim X - \dim \tilde{Z}} \xrightarrow{\wedge} \omega_X$ is a perfect pairing it induces an isomorphism $\Omega_X^{\dim X - \dim \tilde{Z} } \simeq \mathrm{Hom}(\Omega_X^{\dim \tilde{Z}}, \omega_X)$. Hence we've assigned a cohomology class, say $\eta(Z) \in H^c(X, \Omega_X^c)$ to $Z$. Well, strictly speaking we've assigned it to the morphism $f : \tilde{Z} \to X$; it'd take more work to prove $\eta(Z)$ is idependent of the resolution $ \pi : \tilde{Z} \to Z$ (idea: any 2 resolutions of $Z$ can be dominated by a third).

Variations de structure de Hodge et zéro-cycles sur les surfaces générales, where the author give a cycle class in $H^2(X,\Omega_X^2)$ $\endgroup$ – mwZhang May 20 '15 at 1:13