One of my friends has a moderately big WordPress news blog and the load speed was awefully slow. He had asked me to see if I can help with loading pages faster.
Google Adsense ads is his primary source of income and I was shocked by the way, he used the Google Adsense code, in his blog. I told him that there is a better way to use Google Adsense code in WordPress and here I’m writing this blog post.
If you’re likely to follow along, I assume that you already have a Google adsense account and you’re familiar with WordPress widgets.
Let us say, you have the following code from Google Adsense dashboard.
Rather than using the
<script> tag directly, we must use WordPress’s
wp_enqueue_script function to include scripts on the page.
If you’re using WordPress 4.8+, remember to paste the code in ‘Text mode’ under ‘Text’ widgets.
Learn more about the differences between
async attributes here.