For example, I create a file: json.php, and I put it in the wp-content
folder and try to acess it like that: www.example.com/json.php, but I
get the error.
That is because the path is wrong. If you put the file in your theme the path to the file is http://example.com/wp-content/themes/your-theme-name/your-file.php
, not http://example.com/your-file.php
. That path points to the server document root, not to a file in your theme directory.
WordPress and the server conspire to lie about the location of files, at least when pretty permalinks are on. If they are off you will notice that most requests go through index.php
and pages are loaded via various $_GET
parameters but are not loaded directly.
It is not clear what you are trying to do but you can
- Use the correct path to the file
- Put the file in the document root
- Create a custom page template that will work with WordPress’ rewriting mechanisms
- Rewrite the path yourself using
.htaccess
rules. - Use the AJAX API if appropriate