Saturday, 14 April 2012

Hiding CSS from W3C's validators

While trying out a different web font for my portfolio, I noticed that Open Sans caused my site to fail validation whereas Ubuntu did not (issue is on Google's end, but a failure nevertheless). This led me to seek out a way to prevent W3C's CSS validator from parsing Google's stylesheet and I came up with the following code:
$browser = $_SERVER['HTTP_USER_AGENT'];
if( strpos( $browser, 'W3C_CSS_Validator_' ) === false )
echo( "<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />" );