[英]wordpress prevent error reporting
我正在制作自定义主题并注意到一件事。 例如,当我尝试通过url(或任意页面)直接转到主题主题index.php文件时:
localhost/wordpress/wp-content/themes/my-theme/index.php
将出现此错误。
Fatal error: Call to undefined function get_header() in ... on line...
我尝试下载并激活其他主题,但结果是相同的。 我如何防止这种情况发生?
我尝试将以下行添加到wp-config.php
error_reporting(0);
@ini_set('display_errors', 0);
但没有结果。 我也对其进行了“实时”测试,但没有结果。
提前致谢。
如果我错了,请纠正我,但是当有人尝试直接访问主题的index.php时,会发生该错误。 例如,当机器人试图访问它时。
您永远不要像这样直接访问它:
<?php get_header(); ?>
而是这样尝试:
<?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.