Donnerstag, 20. November 2014

How to hide webpage parts from Google indexing

prevent indexing page parts
Wishes and needs to hide webpage parts from Google indexing are common. Before i proceed, i make one thing clear:

No tag can exclude webpage part from Google indexing!

The silly advice about a snake oil named googleon / googleoff is mantra-alike repeated in the wild web. The repeating won't make it working: googleon / googleoff do their job only inside of Google Search Appliance environment, said John Müller of Google. Hope we closed this discussion once and forever.

But don't worry! Believe it or not, i have for you whopping 4 workarounds, how to hide webpage parts from Google indexing. Let's look into one by one:

1. How to hide webpage parts from Google indexing with JavaScript

1.1. Requirement: This solution is based on JQuery! To get the solution working JQuery must be included into the file, whose part you want to exclude from Google indexing.

1.2. Solution

1.2.1. Mark up the webpage part you want to exclude from indexing with
<span class="hidden">Page part excluded from indexing</span>
1.2.2. Add to your CSS following rule:
.hidden {display:none;}
1.2.3. Create a JavaScript file with following content:
<script> 
$(document).ready(function()
{
$(".hidden").show();
}
</script>
1.2.4. Include this file at the bottom of your page with
<script src="hiddenpart.js"></script>
</body>
1.2.5. Even though Google announced recently webmasters should let javascripts become indexed, add this rule to your .htaccess:
<FilesMatch hiddenpart.js>
  Header set X-Robots-Tag "noindex, nofollow"
</FilesMatch>

2. How to prevent Google indexing of webpage parts with iframe

2.1. Cut the webpage content you want to exclude from indexing, paste it in the new file and save it like hiddenpart.php

2.2. Add to the <head> area of hiddenpart.php this rule to prevent indexing:
<meta name="robots" content="noindex, nofollow" />
2.3. Add befor the opening <head> tag, just at the beginning of the hiddenpart.php following code snippet to add noindex rule to the http request header:
<?php
header("X-Robots-Tag: noindex, nofollow", true);
?>
2.4. In the page, where the hidden from indexing content part should appear, add following code snippet:
<iframe src="hiddenpart.php">your browser doesn't support frames? that's weird!</iframe>

3. How to hide webpage parts from Google indexing with iframe and subfolder

3.1. Repeat steps 2.1. to 2.3.

3.2. Create a subfolder /noindex and place into it the hiddenpart.php. Then create in the /noindex subfolder 2 files: robots.txt and .htaccess.

3.2.1. Content of robots.txt:
User-agent: * Disallow: /
3.2.2. Content of .htaccess:
<FilesMatch hiddenpart.php>
Header set X-Robots-Tag "noindex, nofollow"
</FilesMatch>
3.3. Repeat step 2.4.

4. How to exclude page parts from Google indexing with object and data tags

4.1. Repeat steps 2.1. to 2.3.

4.2. In the page, where the hidden from indexing content part should appear, add following code snippet:
<!--[if IE]>
<object classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" data="hiddenpart.php">
</object>
<![endif]-->

<!--[if !IE]> <-->
<object type="text/html" data="hiddenpart.php" style="width:100%; height:100%">
</object>
<!--> <![endif]-->

Happy hiding!
Another technology to hide content parts from Google indexing is to make the page part, which is going to become hidden, as image and embed it into the page. But with this method one must care about how to make this embedded image responsible. This will be one of the next articles, about how to embed images and keep website responsible.
Yandex.Metrica