Support » Fixing WordPress » Custom “not found” pages?

  • Let’s say there’s an errant link on my site (ex: /index.php?cat=99, where there’s no such category)
    Currently, it just returns the main template with the content area blank. Is there a way to have it display a custom message? I’ve noticed (by accident) the WP site does this…

Viewing 9 replies - 1 through 9 (of 9 total)
  • From :
    Creating a custom 404 page is easy! This will allow a more professional presence as it allows when your site users type in a wrong address or page you to keep your site’s design and appearance in tact. 404 error is the error that is given to users as “page not found”.
    You will need ftp or telnet access to set the custom 404 error page up. Start by creating a file in your main html dir called “.htaccess” , the first line of this file should be:
    ErrorDocument 404 /404.html
    You then just simply create a web page and name it 404.html and place it in the same directory. If you users type in a page that does not exist then they will be forwarded to your custom 404 page and your site can maintain the professional image you need.

    Not a custom 404 message…that I can do for my site. I’m talking about when there’s an invalid string in WP. Per my example, if there’s a link to /index.php?cat=99, index.php is a valid page (my WP template), so there is no 404 error. However, there’s no category 99 in my WP installation, so it returns an empty template (well, the template has everything it should, but the content area is blank.)
    Go ahead, try it on you own site: enter a non-existant cat and see what happens. Now, try it again here on the WP site. Try this:
    See, it doesn’t return a blank template, but a “stock” message….
    That’s what I’m trying to figure out.

    I don’t think it was so much the page didn’t exist…. but rather the post didn’t exist… WP will return the page, but with no content where the post should have been. At least that’s how I understand the problem.

    Yes, that’s the problem…”WP will return the page, but with no content where the post should have been.”
    I know it can be done (to have custom content returned) because it’s working on this site (the WP site.) Typing *any* non-existant post/category/whatever serves up a stock message.

    Here is something you could try.
    In your blog.header.php (in the root of your WordPress folder) find the line below:
    $posts = $wpdb->get_results($request);
    Add this just below that line:
    if ($posts == ”) {
    $cat = ”;
    include($abspath . ‘blog.header.php’);
    This way, every errant request coming to your blog will be greeted with the default blog template with all posts from all categories.You could modify this to get other output.
    PS: Those are two single quotes, not a double quote.

    Ah..sorry, I misunderstood. Interesting question, and hopefully someone has the answer. 🙂

    I’ll give that a try. Thanks!

    Works great. I’ve added $p=”; just below $cat=”; so that it’ll trap both errant/removed categories and posts. (Otherwise, a link to a deleted post would return a cgi error.) I even played around with putting in a category number or post number, instead of ”, and it works like a charm.
    What does the include($abspath . ‘blog.header.php’); line do? Is that what’s sending the user back to the default blog template? How could I direct them to a different page instead? I thought about creating either a post or a new category for my custom “not found” page, but I would still run into the problem of that new category/post showing up where I don’t want it. (The category showing up in the category list, and the post showing up on the index page….)
    For now, though, redirecting back to the main template is fine.

    After you reset the category with $cat=” (and page variables in your case), another access is made from the database. blog.header.php sets up the Mysql queries for the database access and then creates the list of posts for the index.php. As long as you are wanting to create a page inside WP (a single post, category, date, search form etc) you will have to call blog.header.php again or make the MySql queries yourself.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom “not found” pages?’ is closed to new replies.