Fatal error: Call to undefined function get_header(), Most Theme Failed

wordpress

#1

Hello WordPress Developers,

I got this erros messages when I check my site like below

mysite.com/wp-content/themes/mythemes

When I visite that url, it give me this message

Fatal error: Call to undefined function get_header() in /users/my-username/www/mysite-folder/wp-content/themes/twentyfifteen/index.php on line 17

You know, the errors messages shouldn’t give us like that, Am I right? And I googled for this and found no better solutions. Here are some steps that I have tried

  • define( ‘WP_MEMORY_LIMIT’, ‘228M’ ); (it doesn’t work)
  • <?php @get_header(); ?> (it can make errors message disappear, but it is not the best solution.)
  • <?php ini_set('display_errors', 0); get_header(); ?> (it can also make errors disappear, but it is also not the right solutions.)

So, I make new wordpress installation( without installing any plugins), it still give me that errors message.

What I understand on this errors, wordpress can’t load

So, do you have better solution to handle this kind of errors? Please advice me, I have spent 3 hours for this.

If we can’t prevent this errors message, should we handle with .htaccess file. Is that good method?

In my point of view, if hacker got this message “He would get username of your domain file path”.

By the way, Have you checked your wordpress site? You will see your file path username is on the errors message. Some of the site take care of that errors. But I don’t know how to handle that,

Please share and advice on me. Thanks in advanced!


#2

Just put this at the beginning of any theme php file

if ( ! defined( 'ABSPATH' ) ) exit;