Wordpress 404 Error with direct php file access

I have a php file that contains a script in my wordpress theme folder that I am trying to view directly through the relative path in the browser, for example: www.mywebsite.com/wp-content/themes/my-theme -name / file-in- question.php

however wordpress gives a 404 error as soon as I try to view it directly.

I would create a template in wordpress, but for the script to work, I needed to view it with the .php extension in the browser, because basically it was a user search in another external wordpress script that returns these results:

www.mywebsite.com/wp-content/themes/my-theme-name/file-in-question.php?controller=Listings ecc ....

All I need is to be able to view the php file without wordpress, giving me a 404 error

I should also mention that this happens with any other php file in the subject. I can use html files and images (placed them for the purpose only in php file extensions.

Thanks in advance.

+4
source share
2 answers

I managed to place this file outside of wordpress and then call functions on the wordpress site. Not neat, but works.

0
source

For security reasons, WordPress will not allow you to go directly to this file. It’s best to give it a template name, assign it a page, and then go to that page.

<?php /* Template name: Your template */ code ?> 

This should run the code that you need, and you can restrict access to the public if you need in the page settings.

0
source

All Articles