Forums

Most Efficient way to Run custom PHP Code in WordPress page? (2 posts)

  1. universaltruth
    Member
    Posted 1 year ago #

    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.

  2. elfin
    Moderator
    Posted 1 year ago #

    Why not have a look at creating a shortcode?

Topic Closed

This topic has been closed to new replies.

About this Topic