Title: Adding PHP code to a page
Last modified: August 19, 2016

---

# Adding PHP code to a page

 *  [josephmo](https://wordpress.org/support/users/josephmo/)
 * (@josephmo)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/adding-php-code-to-a-page-1/)
 * I have some PHP code that interfaces with a database, retrieves information (
   picture, names, etc), for a number of people. In a standalone web page, the code
   generates the HTML code to make this happen. What do I need to do to get this
   code to run and display inside one of the pages on my WordPress installation.
 * Regards,

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/adding-php-code-to-a-page-1/#post-1135859)
 * Couldn’t you just put the code in a [Page Template](http://codex.wordpress.org/Pages)?
 *  Thread Starter [josephmo](https://wordpress.org/support/users/josephmo/)
 * (@josephmo)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/adding-php-code-to-a-page-1/#post-1135895)
 * Thanks for the tip. I’m going to try it.
 *  [Adam W. Warner](https://wordpress.org/support/users/awarner20/)
 * (@awarner20)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/adding-php-code-to-a-page-1/#post-1136192)
 * @ MichaelH,
 * I have the same question, but can’t use a page template. The reason is that I
   need to be able to use the visual editor on this page still (someone will be 
   changing the content regularly on this page), but I have a custom query that 
   I would like to run on this page.
 * Is it at all possible to run PHP in regular WordPress pages?
 *  [Daynah](https://wordpress.org/support/users/phpprincess/)
 * (@phpprincess)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/adding-php-code-to-a-page-1/#post-1136193)
 * [@awarner20](https://wordpress.org/support/users/awarner20/), yes it is. You 
   would need to edit the default Page Template — it’s usually named page.php in
   your theme set.
 *  [Adam W. Warner](https://wordpress.org/support/users/awarner20/)
 * (@awarner20)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/adding-php-code-to-a-page-1/#post-1136194)
 * Hey there phpprincess, nice to see you here…
 * Unfortunately, I don’t think your method will work as this custom query would
   be different on many pages (at least 30). Unless I had one really long if statement
   perhaps?
 * I did try the exec-php plugin, but in order to use that I would need to disable
   the Visual Editor, which would negate my purpose in trying retain the editing
   page feature for the user that will be editing these pages.
 * For now, I am just using separate page templates, each with custom queries, and
   each with static HTML. If this needs to be changed by the user, I’ll just have
   to make those changes for now.
 * p.s. These are category page templates.
 *  [ssgupta](https://wordpress.org/support/users/ssgupta/)
 * (@ssgupta)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/adding-php-code-to-a-page-1/#post-1136195)
 * Try exec-php – [http://bluesome.net/post/2005/08/18/50/](http://bluesome.net/post/2005/08/18/50/)
 *  [Adam W. Warner](https://wordpress.org/support/users/awarner20/)
 * (@awarner20)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/adding-php-code-to-a-page-1/#post-1136196)
 * @ ssgupta,
 * Thanks, but as noted in my previous post above, exec-php will not work for my
   needs.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Adding PHP code to a page’ is closed to new replies.

## Tags

 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 7 replies
 * 5 participants
 * Last reply from: [Adam W. Warner](https://wordpress.org/support/users/awarner20/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/adding-php-code-to-a-page-1/#post-1136196)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
