AdSense Secondary Domain

Showing posts with label webmaster. Show all posts
Showing posts with label webmaster. Show all posts

Thursday, September 14, 2017

How to add amp-auto-ads code to Wordpress site which uses "AMP for WP"

I've installed "AMP for WP" after Google started punishing it in search results for not having Accelerated Mobile Pages some time ago. And have been playing with it for some times now. The plugin itself is very nice and gives an easy way to set up pages and customize them a bit.

However there doesn't seem to be an easy way to add custom code to the page content itself. There is a way to add code between "<head></head>" tags or to the footer, but there is no such way to do it within "<body></body>" tags. And this is where customized Adsense codes should go if you wish to use some (including responsive ads by the way).

I did get away with using standard plugin way of adding adsense (non-responsive) for a while. However I had to figure alternative way of dealing with this problem today since I've got an invitation to "Accelerated Mobile Pages (AMP) Auto Ads" google labs for my cooking website, enabling of which requires to add some custom code to the AMP page content right after the "<body>" tag.

After few tries to search through forums, FAQs, and websites, this is the solution which I came up with (use it on your own risk, plugin documentation didn't have this hook listed and I had to do some code reviews to find it, so it may not work entirely the way I think, or may stop working in future).

I've hooked into 'ampforwp_body_beginning' (added the following to the functions.php of my theme, replace angled brackets with proper characters and appropriate code in the adsense ca-pub value should you choose to copy/paste the code):

function amp_ads_insert() { echo '<amp-auto-ads data-ad-client="ca-pub-YOUR-CODE-HERE" type="adsense"></amp-auto-ads>'; }
add_action( 'ampforwp_body_beginning', 'amp_ads_insert', 0);

Monday, August 26, 2013

Why "Pinterest Could Not Fetch The Image"?..

It was one of biggest mysteries for me, but since Pinterest was launched and became popular, I was not able to get it working for my cooking website.

At some point I decided that it wasn't meant to be and gave up. And ever since then, I was answering something like "It doesn't work, and I don't know why :(" to every inquiry from my readers on how to pin my recipes.


How to Reproduce The Issue

This is how the issue looked to my readers. An interface to select image opens when I click on "pin" button:

There I can select an image and click "pin it" to receive an interface to describe a pin and select a board:

And then, after I click "Pin It", I am presented with "Whoops! Sorry we could not fetch the image." error:



Pinterest Uses Amazonaws.com for Fetching

I did a bit more digging and now I have an answer to the question which bothered me for couple of years: Pinterest can't fetch the image, despite the fact that it shows it to me, because I have access to my website closed to any host of amazonaws.com / Amazon Cloud origin, and Pinterest seems to use services hosted on amazonaws.com to fetch images (at least for some actions).

I did close access from amazonaws.com while back to prevent getting click bombed on my AdSense ads, tons of invalid clicks seemed to come from visits from amazonaws.com. I never understood what was causing them, but denying access for everything of amazonaws.com origin fixed the problem once and for all.

Or until I wanted to have my recipes pinnable by Pinterest...


How to Fix The Issue?

So if you have similar issue like me, I hope I can save you some time trying to figure out how to fix it, like I wish, someone did for me long ago.

Simpler solution is to allow amazonaws.com access your website (that is not a case for me, but it might still work for you).

More elegant solution is to allow only pinterest services to access your website from all the traffic coming from amazonaws.com. If you used the following .htaccess deny rule to restrict that access:

order allow,deny
deny from amazonaws.com
allow from all
Here is an example how you can correct it to allow pinterest traffic through while keeping the rest of amazonaws.com out:
SetEnvIfNoCase Remote_Host "amazonaws.com$" a_robot
SetEnvIfNoCase User-Agent "^Pinterest.*" !a_robot
order allow,deny
deny from env=a_robot
allow from all


Conclusion

Listed solution will only fix the issue with pinning pages, if the cause of it, as I said earlier, is restriction of amazonaws.com traffic access to the website via .htaccess.

Even though mine case was a tricky one to figure out, it isn't the only one out there. There maybe some other reasons why pinterest doesn't do what it is supposed to. I will appreciate if you share yours findings.

Tuesday, February 7, 2012

Google's Recipe Rich Snippets Markup

It looks like I finally managed to convince Google to use recipes info provided in rich snippets info of my cooking site in the search results.

It would be a sarcasm to say it doesn't feel like almost 2 years passed since Google announced recipe snippet format.

And now, after testing over and over, trying couple of different formats, making sure page with markup loads as fast as I can get it to, talking to the silent wall of rich snippet testing tool which gives you everything but useful info about why the formatting of your snippet may be not the correct one and how can you fix it... I finally got it right or at least to the certain extend: review numbers are not showing up in the results, but at least cooking times are and, most importantly, images.

So here are the things which worked for me, maybe some of them will safe some time for you:

  • Scheme.org recipe rich snippet format - easiest and cleanest to implement
  • Hacked wordpress to not use any other microformat: comments template has hcard in markup and post has hentry one that makes them to take over recipe formatting and only comments were showing up in testing tool
  • Removed rel attributes from tag-links, category-links and links in blog roll
  • Made sure that all marked up info is also visible to human visitor, so no <meta itemprop...> unless it is followed with text which explains it
Funny enough that the last issue was pointed to me by Google itself in email with "Rich Snippets Implementation" subject which I received after my second to last attempt to submit my site to rich snippets submission form. I didn't receive any reply from that form submission before, so it felt like I was almost there, just had to fix that small issue with visible content.

Would it be so hard to add this kind of check/error/message to the rich snippet testing tool results, nobody knows...