In the present day, I had to make use of a custom PHP script that I created some time ago in a new WordPress application. Instead of creating a WordPress plugin to deal with this present code, I choose instead to make use of WordPress directly inside my script.
Using WordPress inside your script is a good option if you have a number of customized PHP code.
When you have got a big PHP code base out of your previous growth efforts. There are typically other libraries inside your code, reminiscent of Symfony, Zend Framework, Pear, etc, that you do not wish to take apart. You have got working code and you need it to remain together.
In my case, I had created a type for knowledge collection for a client. But this was no bizarre form. It had over a hundred kind variables. They had been made up of text input, radio boxes, checkboxes, and textarea’s. I wished to use this kind directly inside my WordPress application. Plus I wished the combination to easy.
The solution was really fairly simple.
Existing PHP Code
For example, assume that is my existing PHP code (it is a simple script to illustrate this point).
However the issue is, that is only the shape to gather the data. What about the look and feel of the prevailing site. How can I get the above code to appear like the same template layout of my WordPress application.
For instance, one answer is to add the uncooked HTML. However that is both time consuming, and it isn’t dynamic. If the WordPress template adjustments, I’ve to go in right here and manually change it again. Not something I wish to do.
However that wouldn’t exactly work. I must match the navigation, embrace the style sheets, and make sure the HTML matched exactly the look and feel of my primary website.
The Better Answer
Instantiate WordPress, and use the in-built features inside your code.
Do you see how easy that was? WordPress is instantiated proper in my page. Then I instruct the web page to call the header and footer functions of WordPress.
The header and footer features present every thing I would like for the template of my WordPress site. It automatically populates the HTML, CSS, and any Javascript up on top, and on the underside it closes any tags that were open.
Conclusion
Let PHP do the work. There is no such thing as a must duplicate the WordPress code in pure HTML when you’ll be able to have it generated automatically by WordPress itself.
The added profit is that if the principle WordPress site layout ever changes, the template wrapping your custom PHP code will reflect these Ultimate Member changes immediately.
Paul Markovich is a Lead Technical Trainer.
He has been designing and building customized web sites for entrepreneurs since 1997. He’ll allow you to get the solutions to your burning open source programming questions!
Sorry, there was no activity found. Please try a different filter.