Support » Fixing WordPress » Display wordpress 404 from my script.

Viewing 3 replies - 1 through 3 (of 3 total)
  • designsimply



    To change the 404 error page, you can edit the 404.php file for your theme. The WordPress documentation talks about how to copy the default theme 404 page to your theme if that’s what you’re interested in. See Creating an Error 404 Page.



    No-no, I don’t need to edit 404 page. Sorry if I sounded not correct.

    I do need to call the WordPress 404 page from my own script.
    Lets see what I have now: if my script is called with non existing parameter, e.g.:
    I show that “sorry, such paramenter does not exist”

    Now I don’t want to show my own error. I want to show beautiful and default WordPress 404 page from _my_own_script. I guess I need to call

    How can I call /%themepath%/404.php from my own script and display it? Thanks.

    This is probably 10 months too late for you, but I just had the same conundrum. Here’s the solution I came up with.

    The easiest way to show a 404 page from an arbitrary point in your script would be to define the following function:

    function return_404() {
    	include( get_404_template() );

    and then just call return_404() from wherever you need to. This should work as long as it is called before the headers are sent (I am personally using it on a template_redirect hook).

    I basically copied the above from the same code WordPress uses to display a 404 page when a post is not found. This is as of 2.8, FYI.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display wordpress 404 from my script.’ is closed to new replies.