调用未定义的WordPress函数get_header()错误,但标题仍显示

我正在创建一个自定义WordPress主题, 更具体地说是index.php文件。当我导航到我的网站主页时, 标题正确显示, 但偶尔在服务器日志中显示错误:

PHP Fatal error:  Uncaught Error: Call to undefined function get_header() in D:\home\site\wwwroot\wp-content\themes\OryTheme\index.php:1
Stack trace:
#0 {main}
  thrown in D:\home\site\wwwroot\wp-content\themes\OryTheme\index.php on line 1

我不知道为什么显示标头会给出错误。另外, 如果我删除<?php get_header(); ?>, 将不会显示标题。我可以忽略这些错误吗?

index.php

<?php get_header(); ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
    <h1><?php the_title(); ?></h1>
    <h4>Posted on <?php the_time('F jS, Y') ?></h4>
    <p><?php the_content(__('(more...)')); ?></p>
    </div>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>

<?php endif; ?>
<?php get_sidebar(); ?>

<?php get_footer(); ?>

#1


如果你或其他人尝试访问如下网址:https://yoursite.dev/wp-content/themes/OryTheme

你应该得到一个未捕获的错误:在….错误中调用未定义的函数get_header()。

你或其他人最有可能点击了你网站的直接主题目录, 并且正在执行index.php, 但不幸的是, 你在那里找不到任何wordpress功能。因此, 它正在记录错误。

如果你想摆脱此类错误。你总是可以将这样的代码放在自定义主题和插件的PHP文件的开头。

<?php 
if ( !defined( 'ABSPATH' ) ) exit; // don't allow to call the file directly

// start coding here 

来源:

https://www.srcmini02.com/64807.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37393.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?