HOWTO: Stop robots indexing printer-friendly versions of pages

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
martin42
Forum Members
Forum Members
Posts: 126
Joined: Sat Aug 20, 2005 11:35 pm

HOWTO: Stop robots indexing printer-friendly versions of pages

Post by martin42 »

In case you missed it, there's a cool CMSMS tag called {printer} that makes a link to a printer-friendly version of your web page. I use the following in my Template's Content area, a few blank lines after the content of the page:
 

Code: Select all

<small>Printer-friendly version: {print showbutton="true"}</small>
Now, you don't want Google & co indexing the printer-friendly version of each page.  We can stop this by adding a meta tag to the of such pages:

Code: Select all

<meta name="robots" content="noindex"></meta>
We can do this automatically with a one-line patch to content.functions.php

Code: Select all

diff content.functions.php.ORIG content.functions.php
150c150
<                                       $tpl_source = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'."\n".'<__html><head><title>{title}</title>{stylesheet}{literal}<style type="text/css" media="print">#back {display: none;}</style>{/literal}</head></__body style="background-color: white; color: black; background-image: none;"><form action="index.php?page='.$tpl_name.'" method="post"><input type="submit" value="Go Back"></form>{content}<__body></__html>';
---
>                                       $tpl_source = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'."\n".'<__html><head><title>{title}</title><meta name="robots" content="noindex"></meta>{stylesheet}{literal}<style type="text/css" media="print">#back {display: none;}</style>{/literal}</head></__body style="background-color: white; color: black; background-image: none;"><form action="index.php?page='.$tpl_name.'" method="post"><input type="submit" value="Go Back"></form>{content}<__body></__html>';
Hope this is useful.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: HOWTO: Stop robots indexing printer-friendly versions of pages

Post by Ted »

Nice simple patch.  I've just committed it.
martin42
Forum Members
Forum Members
Posts: 126
Joined: Sat Aug 20, 2005 11:35 pm

Re: HOWTO: Stop robots indexing printer-friendly versions of pages

Post by martin42 »

Wow, that was quick!

Thanks Wishy.
trick

Re: HOWTO: Stop robots indexing printer-friendly versions of pages

Post by trick »

Another thing you could possibly do on the print page is to redirect any external referers to the original page.
mustis

Re: HOWTO: Stop robots indexing printer-friendly versions of pages

Post by mustis »

Printer-friendly version: {print showbutton="true"}

Why does this tag always show the main page inn printer friendly??

If i put this tag in page 3 it always will print page 1

Please help!!
Last edited by mustis on Thu Mar 16, 2006 10:53 am, edited 1 time in total.
Post Reply

Return to “Tips and Tricks”