Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have already asked this question here (StackOverflow link) and the answer has not provided a solution to my problem.

I am getting this error for my site in validation.

Error: A charset attribute on a meta element found after the first 512 bytes.

and here is code I suspect, causing this problem:

<!DOCTYPE html> 
<html class="not-ie no-js" lang="en-US" prefix="og: http://ogp.me/ns#"> 
<head>
    <link rel="stylesheet" type="text/css" href="http://mywebsite.com.au/wp-content/cache/minify/000000/TY3RDsIgDEV_SFb5pAqVgLDWFTb79y6bWXw6ybk3OR4KdcHwgsZxVFLYckzUL97uoN0q7QyqUN6DFpueOAd78Gdqef4ta47EruifwhEzS0WjZfWH97CJSw1FcjdHqOYSc6rkdqdnaU_LdRHW7k79BQ.css" media="all" />
    <script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/hY7RDsIgDEV_aFCXmCzxb5DVDQSKtDj164W5dx977rltV5F8ATDevPRCtAQ02bG2FHcGwV0Z_KNiecOoJz0eg44uac_DCTxDpBlLcp-ibWWh-KNPNyMpz10dztBWRkyiCuaw14exsSTGirpRiWoCl2yoM3JvH2d68l9mW1wWbpJHycbe-0s1tHDLS6GVvg.js"></script>
    <script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/M9YvzdTPKixNLarUK83UK89MSU8t0cvNzAMA.js"></script>
    <script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/ZY5BDsIwDAQ_RNIWxEt4gUkMuKRxsJPS8HpacahQLnuYnZW270btFAO6TDN9xED0BpcsYH6URe1E8dBvoqAmjn4H46ugVIugFO9msKemukF09cqLTeCef42rLqCFEJqNTiD5krcI5FEagZQzJ2z46EC4rMf3BoonTgEqyjw0g8zFPS5vSrieP9rzLriimacv.js"></script>
    <meta charset="UTF-8">

Now I know that <meta charset="UTF-8"> needs to come before the scripts and stylesheets but the problem is that stylesheets and scripts are being inserted by w3tc caching plugin. Is there a way to combat this issue?

share|improve this question

put on hold as off-topic by Pieter Goosen, Johannes Pille, toscho 10 hours ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

I found a solution on this page W3 Total Cache: Better CSS/JS placement. To me it did not work, but it gave me a clue.

I have joined in the wordpress index.php head and meta tags charset.

<head><meta charset="UTF-8">

Next in w3-total-cache/lib/W3/Plugin/Minify.php I change:

preg_match('~<head(\s+[^<>]+)*>~Ui', $buffer, $match, PREG_OFFSET_CAPTURE);

by

preg_match('~<head(\s+[^<>]+)*><meta charset="UTF-8">~Ui', $buffer, $match, PREG_OFFSET_CAPTURE);

both times it is in the code. It runs for me. You can see it in diademas niña

share|improve this answer
1  
Even if I don't have a better solution for you now I do not believe that editing a plugin file is a viable solution. –  kraftner Jun 6 at 7:31

In case you haven't found the solution yet, this worked for me:

Place these comment tags in your theme header.php where you want W3TC to insert the cache files:

<!– W3TC-include-css –>
<!– W3TC-include-js-head –>

Presumably, this would be just after the tag:

<meta charset="UTF-8">

I found it via http://www.sysnovo.com/w3tc-w3-total-cache-tips-tricks.html

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.