I need to run a function when a particular post or page is loaded. Is there any hook that lets me check whether a post is being displayed during page load ?
Leave a Reply
You must be logged in to post a comment.
I need to run a function when a particular post or page is loaded. Is there any hook that lets me check whether a post is being displayed during page load ?
You must be logged in to post a comment.
You can use the
wp
hook and check theglobal $wp_query
object or any conditional.See:
wp
in codex.wordpress.org andwp
in developer.wordpress.orgUse
template_redirect
which is the action hook that fires before rendering the template;I’ve quite often used the following to load in custom meta boxes on pages (rather than custom posts).