You are here:  » 404 Header for Not Found Pages


404 Header for Not Found Pages

Submitted by gregor on Thu, 2012-07-19 02:08 in

I'm using an older version of the WP plugin, but I've looked at the latest code and I think it's the same. I can't find anything about this in the forum, so here goes...

If the product is not found (has been removed from the db), the pto_product function returns nothing. This causes the WP page to show the headings, sidebars, and nothing in the page body. It does not send a 404 header to tell the search engines to remove the page. I looked in pto.php and found where this is happening and tried to add the 404 header, but I got the message saying the header had already been sent (too late I guess). I added a call to pto_search if the product is not found, but that does not always find matches. I also tried adding the featured products as content, but I would really like to send the 404 header. Do you know how we could do this? Is there a WP function that lets you update the header? Do we have access to the section where we could add a robots tag? Could we redirect to a 404 page? Any options? Has anybody else noticed this?

Thanks for your help.
Gregor

Submitted by support on Fri, 2012-07-20 19:55

Hello Gregor,

This should certainly be possible; but as you have identified the existing code is executed after the header has been generated. It will be possible to do but would need to be brought right forward into the pto_init() function in order to send the correct 404 header.

Please bear with me as I only have limited Internet access at this time; but I'll work the code out for you in the most efficient manner, since having made the product SQL query at the pto_init() stage it can be loaded into a global variables upon success to avoid repeating the same query at the existing point...

Cheers,
David.
--
PriceTapestry.com
Please note limited support availability 18-25 July 2012
http://www.pricetapestry.com/node/4689

Submitted by gregor on Sat, 2012-07-21 12:34

Sounds good, thank you. No rush.

Submitted by gregor on Thu, 2015-10-15 03:35

Hi David, I guess I gave up on this issue years ago, but I am back to that site and giving it a quick clean-up between other projects. Did you ever come up with a way to set a noindex on the not-found pages?

It's not a big deal, but if you have a solution in a later version of the plugin, please let me know.

Thanks,
Gregor

Submitted by gregor on Thu, 2015-10-15 05:36

Hi David, I think I figured something out but would like you to take a look if you have a minute.

I added this to the bottom of pto_head

    $prodContent = pto_product(TRUE,TRUE,FALSE,$pto_config_useRelated);
    if(strlen($prodContent) <= 0) {
      print "<meta name='robots' value='noindex,nofollow' />\n";
    }

I had used similar code to insert search results into the page if the product was not found, but I have to admit that I don't really know exactly what this is doing. I don't know if this might cause problems for non-product pages? Maybe I should put it in the switch above under "product"?

Please let me know if you see any issues with this.

Thanks!
Greg

Submitted by support on Thu, 2015-10-15 07:58

That would likely work fine Greg however the tag is likely to appear outside of the <head> element. To include in the header the code can be added to the pto_head() function in pto.php - look for the following code at line 245:

    case "product";
    case "review";

...and REPLACE with:

    case "product";
    case "review";
      if (!count($pto_productResults))
      {
        print "<meta name='robots' value='noindex,nofollow' />\n";
      }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com