20 Jul Integrating WordPress Into PHP Scripts
Now, I had to use a custom made PHP script that I established a though in the past in a new WordPress application. Rather of creating a WordPress plugin to take care of this existing code, I pick out instead to use WordPress directly inside of my script.
Making use of WordPress inside of your script is a fantastic solution if you have a good deal of custom made PHP code.
When you have a big PHP code base from your earlier growth attempts. There are usually other libraries inside of your code, these types of as Symfony, Zend Framework, Pear, etcetera, that you do not want to acquire apart. You have performing code and you want it to keep together.
In my case, I had established a kind for knowledge collection for a consumer. But this was no common kind. It had over a hundred kind variables. They ended up produced up of textual content input, radio containers, checkboxes, and textarea’s. I preferred to use this kind directly inside of my WordPress application. As well as I preferred the integration to effortless.
The resolution was actually fairly easy.
Existing PHP Code
For instance, assume this is my existing PHP code (it is a easy script to illustrate this place).
But the challenge is, that is only the kind to gather the knowledge. What about the glance and truly feel of the existing web site. How can I get the above code to glance like the exact template layout of my WordPress application.
For instance, a person resolution is to increase the raw HTML. But that is both of those time consuming, and it is not dynamic. If the WordPress template improvements, I have to go in below and manually modify it all over again. Not a little something I want to do.
My PHP Sort Page
But that wouldn’t accurately perform. I would have to match the navigation, contain the type sheets, and make certain the HTML matched accurately the glance and truly feel of my principal web site.
The Better Option
Instantiate WordPress, and use the developed in capabilities inside of your code.
Do you see how effortless that was? WordPress is instantiated proper in my web page. Then I instruct the web page to simply call the header and footer capabilities of WordPress.
Allow PHP do the perform. There is no need to have to replicate the WordPress code in pure HTML when you can have it generated quickly by WordPress alone.
The additional gain is that if the principal WordPress web site layout at any time improvements, the template wrapping your custom made PHP code will mirror those improvements immediately.