0

I am trying to check the current url is 404 or not in the pre_option_stylesheet filter hook. As this is the early hook called by wordpress, due to which wordpress default function like is_404 not works. It generates a notice saying:

Notice: is_404 was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.0.) in D:\xamp\htdocs\wordpress\wp-includes\functions.php on line 5229

I also tried to check 404 by using curl(), wp_remote_post(), @get_headers($url) but none of these worked for me.

7
  • Why do you need to do this? What's the problem you're trying to solve that requires this? There's almost certainly a better/simpler solution. Also you should not use the @ operator, it is very bad practice. @ does not fix errors, it silences them, the error still occurs if you use @ it's just not reported to logs – Tom J Nowell Dec 11 '20 at 13:01
  • I have to use different installed theme on 404 page which is not the active theme. For this purpose i have to check 404 condition on pre_option_stylesheet filter hook. – DevD Dec 14 '20 at 7:26
  • Why? Just use the 404.php template in the theme and register different styles and scripts, or better yet just match the .error404 class on the body tag in your stylesheet. If you want your 404 page to look different to the rest of your site, you should ask about that, but loading a completely separate theme is a huge task with lots of unanticipated consequences – Tom J Nowell Dec 14 '20 at 10:01
  • I managed unanticipated consequences of loading a separate theme. It is not just for 404 page but for rest of the pages. I have added option to select different theme on a each page/post. It would not affect rest of the website rather run multiple themes on pages. I managed for pages and posts but the only issue i am facing is with 404 page. – DevD Dec 14 '20 at 11:37
  • How are you doing that though? It's a rather extreme thing to do but there's no code or technical information in your question about how it works – Tom J Nowell Dec 14 '20 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.