简体   繁体   English

WordPress的防止错误报告

[英]wordpress prevent error reporting

i'm making a custom theme and noticed one thing. 我正在制作自定义主题并注意到一件事。 when i try to go directly to my theme index.php file through url (or anypage) for example: 例如,当我尝试通过url(或任意页面)直接转到主题主题index.php文件时:

localhost/wordpress/wp-content/themes/my-theme/index.php

this error will appear. 将出现此错误。

Fatal error: Call to undefined function get_header() in ... on line...

i've tried to download and activate other themes but the result is the same. 我尝试下载并激活其他主题,但结果是相同的。 how can i prevent this from happening? 我如何防止这种情况发生?

i've tried adding the following lines to the wp-config.php 我尝试将以下行添加到wp-config.php

error_reporting(0);
@ini_set('display_errors', 0);

but with no results. 但没有结果。 i've also tested it "live" but with no results. 我也对其进行了“实时”测试,但没有结果。

thank's in advance. 提前致谢。

Correct me if I'm wrong but that error occurs when someone tries to directly access the theme's index.php. 如果我错了,请纠正我,但是当有人尝试直接访问主题的index.php时,会发生该错误。 For example when a bot tries to access it. 例如,当机器人试图访问它时。

You should never access it directly like this: 您永远不要像这样直接访问它:

<?php get_header(); ?>

But rather try it like this: 而是这样尝试:

<?php
  if (function_exists('get_header')) {
    get_header();
  } else {
    // Here goes whatever you want to do when the file is accessed directly.
  }
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM