Wordpress - Hook for post and page load
You can use the wp
hook and check the global $wp_query
object or any conditional.
add_action( 'wp', 'wpse69369_special_thingy' );
function wpse69369_special_thingy()
{
if (
'special_cpt' === get_post_type()
AND is_singular()
)
return print "Yo World!";
return printf(
'<p>Nothing to see here! Check the object!<br /></p><pre>%s</pre>',
var_export( $GLOBALS['wp_query'], true )
);
}
See: wp
in codex.wordpress.org and wp
in developer.wordpress.org
Use template_redirect
which is the action hook that fires before rendering the template;
add_action('template_redirect', 'hooker');
function hooker(){
//I load just before selecting and rendering the template to screen
}