Theory invariance after substitution of theory's field equations back into theory's action functional? Suppose I have a theory $A$ concerning the evolution of a set of fields $T_1, \dots, T_n$. Let the action functional for this theory be $S[T_1, \dots, T_n]$. Suppose in the action, in addition to possible other functions, there is a function $f(T_i, \dots, T_{i + j})$ of a subset of the fields. Finally, suppose the variation of $S$ gives an explicit form for $f$, say $f = g$. My question: If we substitute $g$ for $f$ in the action $S$, does the action still describe the theory $A$?
As a particular example, consider the Einstein-Hilbert action with a matter action
$$
S = \frac{1}{\kappa^2} \int d^4x \sqrt{-g}R + S_m.\tag{1}
$$
Variation yields the Einstein field equation (EFE) $R_{\mu\nu} = \kappa^2 T_{\mu\nu} + \frac{1}{2}R g_{\mu\nu}$, whose trace tells us that $R = -\kappa^2 T$, where $T \equiv T^\mu_\mu$. If we substitute this into $(1)$ above, we obtain the action
$$
S = -\int d^4x \sqrt{-g}T + S_m.\tag{2}
$$
My question: does this action still describe GR? I think it should because the action $(2)$ ought to be an extremum precisely when $(1)$ is, but I still have my doubts since the only curvature coupling inherent in the theory $(2)$ is strictly to the metric and none whatever to the Ricci scalar.
 A: TL;DR: Generically$^1$ an action principle gets destroyed if we apply EOMs in the action. 
Examples:


*

*This is particularly clear if we try to vary wrt. a dynamical variable that no longer appears in the action after substituting an EOM.

*The 1D static model $$V(q)~=~\frac{k}{2}q^2+{\cal O}(q^3), \qquad k~\neq ~0,$$ has a trivial stationary point $q\approx 0$. (We ignore here possible non-trivial stationary points for simplicity.) We can replace the potential $V$ with a new potential $$\tilde{V}(q)~=~a+bq+\frac{c}{2}q^2+{\cal O}(q^3), \qquad \qquad c~\neq ~0,\qquad b~=~0,$$
without changing the trivial stationary point $q\approx 0$. 
Note that it is crucial that $b=0$, i.e. it only works for a zero-measure set. 

*For the 2D kinetic term $L=T = \frac{m}{2}\left(\dot{r}^2+r^2\dot{\theta}^2\right)$ in polar coordinates, if we substitute the angular variable $\theta$ with its EOM, the remaining Lagrangian for the radial variable $r$ gets a wrong sign in one of its terms! See e.g. this & this Phys.SE posts for an explanation.

*Specifically, we can not derive EFE from OP's action (2).
--
$^1$ The word generically means here generally modulo a zero-measure set of exceptions. 
