简体   繁体   中英

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:

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

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. 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.
  }
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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