We look for algebraic certificates of positivity for functions which are not necessarily polynomial functions. Similar questions were examined earlier by Lasserre and Putinar [Positivity and optimization for semi-algebraic functions (to appear), Proposition 1] and by Putinar [A Striktpositivestellensatz for measurable functions (corrected version) (to appear), Theorem 2.1]. We explain how these results can be understood as results on hidden positivity: The required positivity of the functions implies their positivity when considered as polynomials on the real variety of the respective algebra of functions. This variety is however not directly visible in general. We show how algebras and quadratic modules with this hidden positivity property can be constructed. We can then use known results, for example Jacobi’s representation theorem (Jacobi in Math Z 237:259–273, 2001, Theorem 4), or the Krivine-Stengle Positivstellensatz (Marshall in Positive polynomials and sums of squares. Mathematical Surveys and Monographs 146, 2008, page 25), to obtain certificates of positivity relative to a quadratic module of an algebra of real-valued functions. Our results go beyond the results of Lasserre and Putinar, for example when dealing with non-continuous functions. The conditions are also easier to check. We explain the application of our result to various sorts of real finitely generated algebras of semialgebraic functions. The emphasis is on the case where the quadratic module is also finitely generated. Our results also have application to optimization of real-valued functions, using the semidefinite programming relaxation methods pioneered by Lasserre [SIAM J Optim 11(3): 796–817, 2001; Lasserre in Moments, positive polynomials and their applications. Imperial College Press, London, 2009; Lasserre and Putinar in Positivity and optimization for semi-algebraic functions (to appear); Marshall in Positive polynomials and sums of squares. Mathematical Surveys and Monographs 146, 2008, page 25].