We look for algebraic certificates of positivity for functions which are not necessarily polynomial functions. Similar questions were examined earlier by Lasserre and Putinar and by Putinar. 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 or the Krivine-Stengle Positivstellensatz 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.