1

Google search console is complaining that my WordPress theme folder returns a 500 error.

You can see it here https://www.dailywritingtips.com/wp-content/themes/dailywritingtips/

Curiously many WordPress sites have this problem, even very popular ones like TechCrunch https://techcrunch.com/wp-content/themes/techcrunch-2017/

I'm guessing the correct return should be 404 or 403.

I'm not able to simply throw an empty index.php file inside the folder because there is one there already from my WordPress theme.

The 500 error probably appears because the index.php file inside that folder calls WordPress functions that don't exist when you access the Folder directly.

What would be the easiest way to solve this problem?

  • You shouldn't see anything when accessing the theme directory directly, and it will probably throw errors. The index.php file in it is not intended to be accessed directly. The problem is that Google shouldn't be trying to crawl this directory at all. It suggests you, or someone, has put a link directly to the folder somewhere and Google has crawled it. If the error's a concern then you need to find and remove this link, or add the directory as noindex to a robots.txt file. – Jacob Peattie Aug 23 '18 at 15:28
  • If you check this on the blog of Matt Mullenweg you will see that it returns a 404 error, and not a 500 -> ma.tt/blog-content/themes/ma.tt . it makes no sense to return a 500 error when this is not a server problem – Daniel Scocco Aug 23 '18 at 15:31
2

Adding this code to the top of the index.php file in your theme will return a 403 if the theme directory is accessed directly:

if ( ! defined( 'ABSPATH' ) ) {
    header( 'HTTP/1.0 403 Forbidden' ); 
    die();
}

However, you never see that code in any theme's index.php file, because it's unnecessary. I only include it so that this answer has an actual solution in it before I try to convince you you don't actually need to solve anything:

it makes no sense to return a 500 error when this is not a server problem

There is a server problem if you try to access a PHP file, index.php, which is not supposed to be accessed directly.

There are dozens and dozens of files in WP that will throw an error if you try to do this, like these:

https://www.dailywritingtips.com/wp-content/themes/dailywritingtips/functions.php https://www.dailywritingtips.com/wp-settings.php

The only reason you're not getting crawl errors on those is because there's no links to them anywhere and Google's not trying to crawl them (don't worry, links on this site are nofollow).

So your actual problem is Google attempting to index this URL, which would be happening because there's a link to it somewhere that Google has crawled.

The solution to that is to find out why Google is crawling this URL to begin with and removing the link that's responsible, but frankly, if you can't find it, I wouldn't spend any more time on it.

Google's seeing an error response code on a URL you don't even want indexed, and users shouldn't be accessing anyway, so this isn't actually causing any problems. Like you said, this happens on some pretty popular sites, even ones from WordPress VIP like TechCrunch, and they're doing just fine.

  • 1
    I agree with your analysis. However Google search console does not disclose which page is linking there, so unless I fix it some other way Google will keep this error live on search console. thanks for your answer – Daniel Scocco Aug 23 '18 at 20:10
  • Instead of a 403, I'm using header( 'HTTP/1.1 301 Moved Permanently' ); header( 'Location: /' ); – Richard Jan 3 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.