Support » Plugins » Hacks » can I run a PHP file from a wordpress page or post?

  • edpattermann



    I am porting an existing (non-Wordpress) site to WordPress

    the existing site executes php files, with arguments, to return results from a MYSQL database. the results are output in an HTML table.

    a sample call would be something like this


    i do not want to reinvent the wheel. A lot of work has gone into tour.php, and other files like it, on the existing site.

    can I execute that tour.php file, as in the above example, and return the results to a wordpress page?

    with static calls and arguments, or ones generated on the fly?
    any issues with performance?

    thank you.

    — Ed

Viewing 7 replies - 1 through 7 (of 7 total)
  • WordPress Shortcodes are pretty close to what you are doing. If you convert tour.php into a plugin that defines a Shortcode called [tour], you will have pretty much the same as what you had on your non-WordPress site. And have the best combination of performance and ease of implementation.

    This might be a good place to start reading:



    Take a look at this plugin it may be what you are looking for.

    I use it mostly in the form of putting small PHP snippets inside of a widget. You could look at creating a new page template with a widget area to house your tour functions.

    Then create a new page Tour (or what ever) and choose the Tour Template for that page.

    Could be a quick and easy solution for you.

    101Phil is right, in terms of quick implementation, but I made my recommendation based on performance.

    If you prefer 101Phil’s approach, please also consider:
    I looked at all alternatives, including Phil’s suggestion, and found this one offered the most security.



    Thanks for all the responses so far. I am not dealing with small pieces of code, but large PHP files.

    So the idea of turning that code into a plugin sounds more reasonable.

    That is beyond my skill level though.

    Anyone out there want to help me?

    To convert a .PHP file into a shortcode inside a plugin, you make it into a function that returns rather than echos all its results. Then you do an add_shortcode to say that [myname] activates php function edp_myname() (be very carefuly to keep function names unique in WordPress by prefixing). A Plugin has a special header of comments at the beginning of its php file, and you can define as many shortcodes as you want in a single plugin.

    There are lots of details in, but I personally found the concept of plugins too daunting so bought a book and was a lot happier when I first started. My fav. is Professional WordPress Plugin Development by Brad Williams, Ozh Richard and Justin Tadlock.



    Nice one Jonradio,
    I think I’ll use that suggested plugin too, next time round. or use your suggestion and go the short code route. Ps I have a post on here I’m stuck with, if you don’t mind I will PM you for some advice.

    Keep us posted on your project Ed. Also if you dont have time/expertise, you could look at (or insert other site here) as a way of getting the functionality built.

    101Phil: I have responded in the support thread for your problem that you are referring to.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘can I run a PHP file from a wordpress page or post?’ is closed to new replies.