最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - Fatal error: Call to undefined function get_header()

programmeradmin2浏览0评论

Hello WordPress Developers,

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

mysite/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); ?> (it can also make errors disappear, but it is also not the right solutions.)
  • So, I make new wordpress installation, it still give me that errors message

Please note: I don't install any plugins

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

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

Hello WordPress Developers,

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

mysite/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); ?> (it can also make errors disappear, but it is also not the right solutions.)
  • So, I make new wordpress installation, it still give me that errors message

Please note: I don't install any plugins

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

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

Share Improve this question edited Oct 17, 2015 at 5:16 Mark Kaplun 23.7k7 gold badges43 silver badges65 bronze badges asked Oct 17, 2015 at 5:03 PorPor 4024 silver badges12 bronze badges 3
  • Template files are not intended to be loaded directly and you shouldn't do it. If you do that, WordPress engine is not loaded and functions from WordPress, like get_header(), doesn't exist; that is why you get the error "Call to undefined function get_header()" – cybmeta Commented Oct 17, 2015 at 8:24
  • Hello @cybmeta ... I am agree on your talks, but you know, I don't wanna let that error happen like this, if hacker check like that, he would get user name from the errors message url. Check my Question errors message. But you know, [www.wpbeginner] doesn't happen like that. That site can handle well, I think that they handle those files through .htaccess. How do you think? – Por Commented Oct 17, 2015 at 11:15
  • 1 You can use a firewall, like wpbeginner does, or just verifiy that WordPress is loaded at the top of the PHP file. For example with if ( ! defined( ‘ABSPATH’ ) ) exit;. Anyway, you don't really need that. – cybmeta Commented Oct 17, 2015 at 12:49
Add a comment  | 

2 Answers 2

Reset to default 3

I got your point What you are trying to do. The solution to your problem is these lines of code to place above all the code of your index file or you may place it on all files of your theme.

<?php

// Do not allow directly accessing this file.
if ( ! defined( 'ABSPATH' ) ) {
    exit( 'Direct script access denied.' );
}
?>

As per described by you I thought you had issue with the theme. Can you switch the theme ?

If its not possible with backend then Try with FTP just rename that theme folder to another name & then Look whats happen. If it still exist then you need to try it with disabling all plugin at once & then activate one by one to check which plugin will cause this issue.

I hope this will help you out in fixing this issue.

发布评论

评论列表(0)

  1. 暂无评论