You are here:  » Better 404s in WordPress


Better 404s in WordPress

Submitted by cascadeclimbers on Tue, 2018-01-16 18:54 in

Hi David,

To give a bit of backstory, we did a major upgrade on our site, one of those changes involved going from standalone to WP version of pricetapestry. Everything looks and works great now across our site, but Google hasn't been too happy about so many changes. One of the things I shouldn't have done, which is now exposing a problems, is that I added a ton of new products, from ~130k to 300k+. One of the feeds in particular has a lot of product turnaround and I'm not happy with how many 404s it's throwing, so short story long I'm wanting to drop a lot of the feeds I added. Which will obviously create 100k+ 404 pages. Right now the 404 page in pricetapesty is a simple "OOPS! THAT PAGE CAN’T BE FOUND." which I'm pretty is just the standard WP 404 page. What I'm hoping to have instead is a page that shows similar products instead, a custom 404 page for price tapestry. Would this be something you would be willing to put in an update?

Thanks, Jon

Submitted by support on Wed, 2018-01-17 10:43

Hello Jon,

It's no problem to not set the 404 and have the page display Related Products instead - to try this, edit pto.php and look for the following code beginning at line 529:

        $wp_query->set_404();
        return;

...and REPLACE with:

        $pto_productResults[0]->name = $pto_product;

Cheers,
David.
--
PriceTapestry.com

Submitted by cascadeclimbers on Wed, 2018-01-17 18:44

Thanks David! That works, however I seem to be getting a php warning with that.

Warning: Creating default object from empty value

Submitted by support on Thu, 2018-01-18 11:23

Hi,

Have a go with:

        $pto_productResults[0] = (object) array("name"=>"");
        $pto_productResults[0]->name = $pto_product;

Cheers,
David.
--
PriceTapestry.com