• Love the theme but not its 404 page with the George Orwell quote and the misspelled Ooops. I’ve read a lot of other posts related to “fixing” the 404 page but nothing that suggested how to “replace” it.

    I did find a really simple way to do it but it isn’t permanent because it involves adding a 404.php file to the theme’s folder. (I used FTP to copy the 404.php file from another theme – twentyten – and store it in wp-content/themes/customizr. Changed permissions to rw-r–r–.) This works but when the theme is updated, that file gets deleted. For now, I just copy it back in.

    I have tried putting the 404.php file in my child theme folder but it gets ignored completely. Is there some code I can add to my child theme’s functions.php file that would cause it to use the 404.php file in my child theme folder?

Viewing 7 replies - 1 through 7 (of 7 total)
  • If it’s just the words you want to change, you can do that with the following added to your child theme’s functions.php file:

    // set 404 texts
    add_filter( 'tc_404', 'my_404');
    function my_404() {
    
    		return array(
    			'quote'             => 'ADD A QUOTE IF YOU WANT TO',
    			'author'            => 'ADD AN AUTHOR IF YOU WANT TO',
    			'text'              => 'PUT YOUR TEXT HERE'
    		);
    
    }

    If you don’t have a child theme and a functions.php file, read How to Customize Customizr.

    Thread Starter dccharron

    (@dccharron)

    Much appreciate the reply and the snippet of code.

    I do have a child theme so that’s no problem.

    I must confess I had an ulterior motive. I wasn’t just looking to change the 404 response page. I also wanted to generate 410 errors for some pages so that the search engine crawlers remove them from their list of indexed pages. As you know, 404 just means “temporarily unavailable” so the search engines keep them in their index tables and their crawlers keep coming back to check for the same page over and over. They just keep getting flagged as errors in webmaster tools.

    To overcome this I found a nice plugin that can generate a 410 error for nominated pages. 410 flags the page as “removed”. So the page gets removed from the search engine index and the crawler won’t come back for it. That plugin lets you generate a friendlier 410 error page by having your own 410.php file. They recommend copying your theme’s 404.php page in your theme’s folder and renaming it to 410.php. But “customizr” doesn’t have one. (That’s not a criticism just an explanation for using the 404.php page from another theme which led me to discover that I could use it to replace to replace Customizr’s 404 page.) Sadly, both php files get blown away when “customizr” is updated.

    So my question about the 404.php file was really trying to find a way to retain a file in the theme folder across an update. I was hoping to find a way to put the files in the child theme folder and have them used from there. I realise that this is quite esoteric so I would understand if this is outside the scope of “theme support”. But just in case, I thought I would ask.

    For now, I’ll keep my 404.php and 410.php files in my child theme folder and just copy them back into the theme folder after each update. A bit messy but it works.

    You should be able to put them in a child theme‘s folder, no?

    Thread Starter dccharron

    (@dccharron)

    I can’t believe it. I just tried it again and this time, it worked! Perhaps I hadn’t changed my file properties. No I have them as rw-r–r– and it’s great. Both the 410.php and the 404.php in the child theme’s folder are active. Great. Thank you very much.

    And thanks for teaching me about 410s ??

    [ I presume you know about 301s, which would allow you to redirect the traffic somewhere else? ]

    Thread Starter dccharron

    (@dccharron)

    I must confess I had not thought about using 301 and I’ve found two plugins for this too. (After you mentioned it I went off and did more reading. I had associated 301 with a change of domain name but now I realise that it can be used for lots of other situations where the URLs change.)

    With hindsight, I could have used 301’s in this case (I moved a small website from Windows-based .NET server to Linux with WP running on Apache). I can see that it would not have been a trivial process because the URL structure of the old web site was so radically different. I guess the question to ask when deciding if 301 is better than 410 (or 404) is whether there is any benefit in retaining the legacy page URL for ratings by the search engine or if you have a lot of external links on other web sites pointing to your old URLs. In this case I’m happy that there was no real benefit. But I’ll keep it in mind for future applications. Good call.

    I think that a 301 even to your home page would be better than a 410, but I’m not an SEO expert.

    I moved from an old site that had fairly good (if narrowly-focussed) rankings to a brand new one and used the redirection plugin to create a rough map between old and new. It wasn’t always perfect, but I figured that redirecting people to something that was half-right was better than shutting down and starting from scratch with the rankings.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Replacing 404 page with my own’ is closed to new replies.