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?
3
Answers
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:
So I created a directory and put my code in it..
And it was then accessible from a url like:
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.
You can add a $_GET OR $_POST to the header as a plugin for WordPress.
You will need a header of the plugin
The first part of the code would be. The code you put in here would show in the header when each page is call
To call the function you need to add this line of code
To learn more about add_action you can read it at
https://developer.wordpress.org/reference/functions/add_action/
After you a Activate the plugin
You can now call your web site with GET or POST base on what you added to the header.
By doing it was a plugin you can use the WordPress backbone function
Good Luck
Karl K
Create a folder in your theme’s root folder called
myCustomDirectory
and place your php file inside that.then add to your functions.php the following:
This will handle the Rewrite Rules:
This will handle the WordPress Query Vars:
This will tell wordpress to pull the correct file:
make sure to flush your rewrite rules when you are done by going to: Settings > Permalinks and clicking ‘save changes’