Jump to content
Latest News: (loading..)
cinolas

Adding NOINDEX to some product pages, based on a field in the Products table

Recommended Posts

Greetings!

I'm using osC 2.3.4 BS with SEO URL's .

I would like to make it so that some of my products don't get indexed by search engine. Those products are clearly tagged in a custom field I created in the Products table.

The problem is that the <head> section of product pages, where I would need to put the NOINDEX tag, gets generated in template_top.php

I don't want to use robot.txt because I would then have to update the list of pages manually... no fun.

Is there any way to query the products record from template_top?
Or a way to add the NOINDEX in product_info where I can check the database field to see if that product needs to be indexed or not?

Or a third method to achieve this that I'm not thinking about right now?

THANKS!!

Share this post


Link to post
Share on other sites

The template_top file gets loaded after the application_top file and the later knows what page is being shown as well as the product. So you just need to have something like this in template_top above </head>. I have not tested this so be sure to check that it works as you want. Note that XX is the product ID.

<?php
if (basename($PHP_SELF) == 'product_info.php && $_GET['products_id'] == XX) ?>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<?php } ?>  

 

Share this post


Link to post
Share on other sites

Something to keep in mind: neither robots.txt nor meta nofollow tags guarantee that a page will not be read and possibly indexed! They are merely suggestions to search engines, but search engines are free to go ahead and index them.

Second, think about why you don't want to index these pages. Should they be indexed, what are the consequences? So long as they are clearly marked as "custom" in some way, and people can see them anyway, why can't search engines see them? Could they be useful as advertising for your other products? Would they do harm to the search rank of your other products? In that case, you might want to think about reorganizing your product pages. Don't forget that some search engines don't like it when they see different content than real people see.


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get (stable) Frozen or (unstable) Edge. See also the naming convention and the latest community-supported responsive "Edge" release

Share this post


Link to post
Share on other sites
On 10/5/2018 at 6:01 PM, Jack_mcs said:

The template_top file gets loaded after the application_top file and the later knows what page is being shown as well as the product. So you just need to have something like this in template_top above </head>. I have not tested this so be sure to check that it works as you want. Note that XX is the product ID.


<?php
if (basename($PHP_SELF) == 'product_info.php && $_GET['products_id'] == XX) ?>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<?php } ?>  

 

@Jack_mcs That's very close to what I need. Two questions: would this work with the SEO URL contrib? My URLs look like this:
/directory/some-product-name-p-1943.html


Is there any way to query another field than products_id using the method above? I would need it to read a custom boolean field in the products table, so it would have to look something like:
(I don't know how $_GET works... or are you getting the products_id from the URL?)

 

<?php
if (basename($PHP_SELF) == 'product_info.php && $_GET['products_custom_field'] == 1) ?>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<?php } ?>  

Thanks a bunch!

Share this post


Link to post
Share on other sites
On 10/6/2018 at 7:55 AM, MrPhil said:

Something to keep in mind: neither robots.txt nor meta nofollow tags guarantee that a page will not be read and possibly indexed! They are merely suggestions to search engines, but search engines are free to go ahead and index them.

Second, think about why you don't want to index these pages. Should they be indexed, what are the consequences? So long as they are clearly marked as "custom" in some way, and people can see them anyway, why can't search engines see them? Could they be useful as advertising for your other products? Would they do harm to the search rank of your other products? In that case, you might want to think about reorganizing your product pages. Don't forget that some search engines don't like it when they see different content than real people see.

@MrPhil All very good concerns, thanks for bringing them up, but I think we're good. It's not mission critical. The specifics of the situation is a bit of a long story, but essentially we're trying to hide products so they are only accessible from certain places. The reason we want those products not to be accessible from search engines is to prevent the user from being confused once they navigate away from the hidden products and can't find it anymore. We want to narrow down the entry points so that the user remembers how they got to it.

Edited by cinolas

Share this post


Link to post
Share on other sites
4 hours ago, cinolas said:

product-name-p-1943.html

The 1943 in the above is the products_id. It is part of the url for the product page so you can use $_GET for it. But products_custom_field isn't part of the url, unless you've changed your code to make it so, so you can't use $_GET to grab it. To check that field, you would need something like this untested code

<?php
if (basename($PHP_SELF) == 'product_info.php) { 
  $custom_query = tep_db_query("select products_custom_field from products where products_id = '" . $_GET['products_id'] . "'");
  if (tep_db_num_rows($custom_query)) {
    $custom = tep_db_fetch_array($custom_query);
    if ($custom['products_custom_field'] == XX) {
    ?>
     <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
    <?php
    }
  }
} 
?>  

 

Share this post


Link to post
Share on other sites
On 10/11/2018 at 5:55 PM, Jack_mcs said:

The 1943 in the above is the products_id. It is part of the url for the product page so you can use $_GET for it. But products_custom_field isn't part of the url, unless you've changed your code to make it so, so you can't use $_GET to grab it. To check that field, you would need something like this untested code


<?php
if (basename($PHP_SELF) == 'product_info.php) { 
  $custom_query = tep_db_query("select products_custom_field from products where products_id = '" . $_GET['products_id'] . "'");
  if (tep_db_num_rows($custom_query)) {
    $custom = tep_db_fetch_array($custom_query);
    if ($custom['products_custom_field'] == XX) {
    ?>
     <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
    <?php
    }
  }
} 
?>  

 

@Jack_mcs Thank you! That's exactly what I needed. I haven't tried it yet, but it gives me enough of a clue that I should be able to make it work if it doesn't outright. Cheers!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×