How does one set cookies in WordPress without getting the ‘headers not sent’ error? within WP

The solution is setting a function that’s hooked into init.

add_action('init', 'stats_cookie');
function stats_cookie()
{
    if(!isset($_COOKIE['site_stats']))
    { 
        $current = current_time( 'timestamp', 1);
        setcookie('site_stats', $current, time()+60+60*24*7, COOKIEPATH, COOKIE_DOMAIN ); 
    }
}