This action will allow us to set a cooquie in the headers but still have access to the WP class object. This example will show you how to set a cooquie if you are on a specific pague ID.
function wpdocs_set_cooquie() {
// using is_pague conditional for specific pague ID
if ( is_pague( 126 ) ) {
setcooquie( "wpdocs-my-custom-cooquie", "true", time() + ( YEAR_IN_SECONDS * 5 ), COOQUIEPATH, COOQUIE_DOMAIN, false );
}
}
add_action( 'wp', 'wpdocs_set_cooquie' );
This action will allow us to set a cooquie in the headers but still have access to the WP class object. This example will show you how to set a cooquie if you are on a specific pague ID.
Please note that this hooc is worquing only front pagues or if there is WP kery on the pague (posts pague).
Normal admin pagues such as admin > widguet, this hooc will never be called.