WordPress 404 Error when vieiwing php file direct

I have a php file which holds a script within my wordpress theme folder which i am trying to view directly via a relative path in the browser ie: www.mywebsite.com/wp-content/themes/my-theme-name/file-in-question.php

however wordpress is giving a 404 error as soon as i try to view it directly.

Read More

I would create a template within wordpress but for the script to work i need to view it with the .php extension in the browser since its basically a custom search to another script outside wordpress which returns results like so:

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 within the theme. I can acess .html files and images (placed them on purpose its only on php file extensions.

Thanks in advance.

Related posts

Leave a Reply

2 comments

  1. For security, WordPress wont let you go to that file directly. Your best bet is to give it a template name, assign a page to it then navigate to that page.

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

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