Integrating WordPress into PHP Scripts
General description
Today, I had to use a custom PHP script that I created a while ago in a new WordPress application. Instead of developing a WordPress plugin to handle this existing code, I choose to use WordPress directly within my script.
Using WordPress within your script is a great option if you have a lot of custom PHP code.
When you have a large PHP code base from your previous development efforts. Usually there are other libraries within your code, like Symfony, Zend Framework, Pear, etc., that you don’t want to disassemble. You have a work code and you want it to stay attached.
In my case, I had created a data collection form for a customer. But this was not an ordinary way. It had more than 100 shape variables. They consisted of text input, radio boxes, check boxes, and text areas. I wanted to use this form directly within my WordPress application. Also, I wanted integration to be easy.
Actually, the solution was quite simple.
Existing PHP code
For example, suppose this is my existing PHP code (it’s a simple script to illustrate this point).
But the problem is, that’s just the way to collect the data. What about the appearance of the existing site? How can I make the above code look like the same template design of my WordPress application?
For example, one solution is to add the raw HTML. But that takes a long time and is not dynamic. If the WordPress template changes, I have to go here and change it again manually. It is not something you want to do.
My PHP form page