404 pages using PHP

I have tried to test pages and 404 using PHP code. An example : https://www.example.com/dffwfw
When I test PHP code it will not push 404 value. How to push PHP code inside 404 template as it is

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


<?php

// Get the current response code and set a new one
var_dump(http_response_code(404));

// Get the new response code
var_dump(http_response_code());
?>

What do you have in your .htaccess file?

# Help management
ErrorDocument 404 /help/error/page_not_found_404_01.html

RewriteRule ^en-GB/help/error/page_not_found_404_01\.html$ index.php?page_id=help_pages_error_404_01 [L]

Well there you go then, you’ll be wanting to change the error document 404 to point to your new 404 page.

And I’m really not sure what your rewrite rule is trying to do but putting one on your error document doesn’t appear to be a good idea.

I agree with you and it needs to be more stable due to templates. There are any WP simplifications…

<?php

$http_response_code = var_dump(http_response_code());
if ($http_response_code == 404){$smarty->assign("http_response_code", '404'); } else {$smarty->assign("http_response_code", var_dump(http_response_code()));}

?>

Is this the correct 404 detection or it can be improved?