Most Efficient way to Run custom PHP Code in WordPress page?
-
What would be the most efficient and effective method of running custom PHP code in a wordpress page, and preserve my theme and layout etc?
For example lets say I wanted to create a simple calculator. It has 2 text boxes so the user can enter 2 numbers and a submit button to calculate the result.
I do not require all the code. I would just like to know the best way of going about this.
Would I create a separate file (for example mycalc.php), insert the code (including classes and styles for the theme) and then upload that file to the root folder of wordpress
or should I enter the code directly into a post after installing a plugin like Exec-PHP.
I’ve read on this page that the second method is less efficient. I quote:
Having installed the plugin, it was simple to create a Page, add some PHP code using the traditional PHP tags . However, once I started writing code in anger, I began to understand that to run the code efficiently, and to give the end-user a good experience, simply placing code in the page (blog entry) is too simplistic.
The key issues, is that the PHP code is evaluated at run-time, using the PHP eval() function. This function is highly inefficient. So, the first improvement was to move the bulk of the code to a separate PHP file and include it. This way, the only code evaluated is the include statement.
The topic ‘Most Efficient way to Run custom PHP Code in WordPress page?’ is closed to new replies.