Search code examples
phpwordpressbitnami

How to add and access custom php code in Wordpress site?


I need to add some of my own php files to an existing Wordpress site (from Bitnami) so it can be accessed from a 3rd-party service. I don't need to access anything from Wordpress in my code, but I need my code to be accessible from a url for 3rd-party services.

Like this:

https://myWordPressSite.com. <- normal WP site

https://myWordPressSite.com/myCustomDirectory/generateSerial.php <- my code https://myWordPressSite.com/myCustomDirectory/doSomething1.php <- my code https://myWordPressSite.com/myCustomDirectory/doSomething2.php <- my code

How can I add my directory of code to the Wordpress file structure, and how to access it from a URL?


Solution

  • It turns out it was much simpler than I thought, or any of the other answers presented here.

    The answer is to just add a directory of my own code inside the Wordpress home folder.

    In the case of a AWS/Lightsail/Bitnami/Wordpress package, the home directory is:

    /opt/bitnami/wordpress
    

    So I created a directory and put my code in it..

    /opt/bitnami/wordpress/myDirectory
    /opt/bitnami/wordpress/myDirectory/generateSerial.php
    /opt/bitnami/wordpress/myDirectory/doSomething.php
    

    And it was then accessible from a url like:

    https://myWordPressSite
    https://myWordPressSite/generateSerial.php //etc
    

    One small catch is that some Wordpress packages and some other Bitnami packages are laid out a bit different, so check on your specific installation.