[wp-hackers] Throw 404 error via plugin

Ryan Bilesky rbilesky at gmail.com
Thu Jan 13 18:26:59 UTC 2011


ok that was wierd.  That sent the header but did not load the 404 error
document, but sending the header then including the 404 template worked,
even though I tried it before and it didn't.  I think when I tried that
originally I didn't use die(); after including the template but this works:

header("HTTP/1.1 404 Not Found");
include(TEMPLATEPATH . '/404.php');
die();

One side effect though, when it loads images for the error document, they
have a 404 status too even though they exist and load properly.  Any idea
how to fix that?

On Thu, Jan 13, 2011 at 9:51 AM, Ryan Bilesky <rbilesky at gmail.com> wrote:

> Ok I spoke too soon, this still is not working.
>
> What I might do is this, create a file call it say 404error.php and it
> would look like this
>
> <?php
>
> include ('./wp_load.php');
> include (TEMPLATEPATH . '/404.php');
>
> ?>
>
> Then set my .htaccess to use this 404error.php as my 404 error document
> then just send the 404 header in my plugin via header();
>
> Not the simplest option but that should work if nobody has any other ideas.
>
>   On Thu, Jan 13, 2011 at 9:03 AM, Ryan Bilesky <rbilesky at gmail.com>wrote:
>
>> Where would I redirect them?
>>
>> I'll try the pre_get_posts hook given the explination I think that should
>> workl. Thanks all for your help.
>>
>> On Jan 13, 2011 2:08 AM, "24/7" <24-7 at gmx.net> wrote:
>> > Don't know if this is true, but here goes my theory: Ryan tries to
>> > bring someone to a 404 page when some condition is not met. So why not
>> > if { bla() } else { wp_redirect('wherever', 404) } ?
>> > _______________________________________________
>> > wp-hackers mailing list
>> > wp-hackers at lists.automattic.com
>> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
>


More information about the wp-hackers mailing list