Title: mySQL database driven WordPress site
Last modified: April 1, 2019

---

# mySQL database driven WordPress site

 *  [johngordon71](https://wordpress.org/support/users/johngordon71/)
 * (@johngordon71)
 * [7 years ago](https://wordpress.org/support/topic/mysql-database-driven-wordpress-site/)
 * I currently work on a few websites that share a mySQL database.
 * We are considering merging the sites into a single WordPress site.
 * However I am unsure if it is (fairly easily) possible to do this, as with WordPress
   you are a bit more limited in what HTML / PHP you can add, or more specifically
   where you can add stuff.
 * I know you can add in custom HTML to WordPress sites, but can you add the PHP
   code and mySQL queries that typically go above the header in a page to a WordPress
   page?
 * Another possibility which has been suggested (not by me) is to use iFrames.
 * So we could create a WordPress site, and embed existing pages on the same domain
   within WordPress pages using iFrames. I’m really not sure what the benefit of
   doing that would be, and seems quite unnecessary if we already have the non WordPress
   pages.
 * Maybe I am missing something though – is there any advantage in this approach?

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

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [7 years ago](https://wordpress.org/support/topic/mysql-database-driven-wordpress-site/#post-11380402)
 * NOOOooo..!! No iframes!! 😀
 * I think you really knew iframes would be a bad approach. It sounds like you have
   the general picture correct and are just a little unsure. You can add anything
   to a WP site within the limits of PHP. However, _how_ you add things is much 
   more strictly managed. To add anything may require custom coding.
 * You can make SQL queries in the head section if necessary. What you ultimately
   output could influence how you add the necessary code. If it can or should be
   fairly late in head output, you can use the “wp_head” action. If it needs to 
   be among other links to external scripts, you can use the “wp_print_scripts” 
   action. If the need is earlier, the code needs to be added to the header.php 
   template of the theme.
 * When templates are involved, it’s best to create a child theme. It’s a good container
   for all custom code anyway. Be aware that many commercial themes take up the 
   child theme slot so you cannot add your own. You can manage templates from a 
   plugin, but it gets rather involved.
 *  Thread Starter [johngordon71](https://wordpress.org/support/users/johngordon71/)
 * (@johngordon71)
 * [7 years ago](https://wordpress.org/support/topic/mysql-database-driven-wordpress-site/#post-11380472)
 * Thanks. I really wasn’t convinced by iFrames, but the client sees it as a way
   of having everything in WordPress. My own view is that its a lot of potentially
   unnecessary reinventing of the wheel.
 * I remember frames from the much earlier days of the web, and how they came to
   be universally derided. My understanding was that iFrames were a bit better, 
   but really as a tool for displaying content from another site within your own
   site.
 * To use them to display our own pages within our own WordPress pages seems a little
   nuts, or is that just me?
 * Do you know a good place to read up on how to use those actions? That’s something
   new to me. I’m OK creating child themes and editing template files though. I’m
   just a little wary of potentially breaking something as WordPress is pretty complicated
   with include files all over the place.
 * I’m used to using Dreamweaver (although mostly code view, I used it originally
   for the old Macromedia server extensions for doing all the SQL stuff that Adobe
   have long since dropped. And for a long time now Web Assist’s extensions for 
   all of that. It tends to put all the relevant PHP stuff above the <header> element.
   I guess a lot of it can go anywhere, but sometimes it seems quite picky in the
   order of PHP code blocks.
 *  [Dan Bailey](https://wordpress.org/support/users/fontosaurus/)
 * (@fontosaurus)
 * [7 years ago](https://wordpress.org/support/topic/mysql-database-driven-wordpress-site/#post-11381366)
 * You’re right re: the IFRAME issue — moreover, it puts them in a position when
   managing content is now spread across two separate WordPress instances. You’ve
   got two different server accounts to manage/secure/maintain, etc.
 * Offhand, I can think of an ugly way to do this — if there’s a subset of them 
   that can be filtered by author, timeframe, and/or Category metadata, that will
   simplify matters. Just dump the XML file (Tools -> Export) from the old site,
   and then do Tools -> Import with the new site, and pull in the XML file. This
   will likely require some post-processing to clean up the post content, etc. If
   there’s posts you don’t want to carry over into the new site, you could either
   edit the exported XML file before importing, or just import everything and delete
   unwanted posts/content via the admin interface.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [7 years ago](https://wordpress.org/support/topic/mysql-database-driven-wordpress-site/#post-11384176)
 * Dan makes a good point about importing existing content into WP. You could in
   theory simply query the existing DB from WP and generate output using custom 
   code on a page template (I think this is essentially what you had in mind), but
   that makes maintaining the existing data difficult. It’s kind of an alternative
   iframe technique, with many of the same disadvantages.
 * It’s better to import data into WP so the data can be easily maintained. It may
   be painful to make the transition, but it’s better to do that now than to continue
   with a bad schema and be constantly fighting it because it was cobbled together.
   If Dan’s XML approach becomes very difficult to pull off and all else fails, 
   a custom export script could be run that converts the data into a valid WP import
   format (basically XML).
 * IMO, the best way forward is a complete reboot of the existing sites into a properly
   put together WP site. Or to be fair, any other popular CMS for that matter. Of
   course we think WP is the best choice, but there are alternatives 😉
 * You may not need action hooks if you end up importing the data, but filter and
   action hooks are the major way that WP is customized and extended to meet site
   owner needs. So they are worth learning about if you are going to be committed
   to WP. Start here: [https://developer.wordpress.org/plugins/hooks/](https://developer.wordpress.org/plugins/hooks/)
 * The above linked handbook is a good reference in general. Its companion is the
   Theme Handbook with more good reference material: [https://developer.wordpress.org/themes/getting-started/](https://developer.wordpress.org/themes/getting-started/)
 * I’m not suggesting you study all of that. They are references to look to when
   you need to figure something out. You may never utilize all of the material presented.
   Study only what you need or have a particular interest in.
 * If you are using Dreamweaver mostly in code mode, you should look at the built
   in WP block editor. It’s not in the same league as Dreamweaver, but its output
   is naturally most compatible with WP. It too has code view, in this mode there
   is little difference, so you may as well use the built in editor.

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

The topic ‘mySQL database driven WordPress site’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [7 years ago](https://wordpress.org/support/topic/mysql-database-driven-wordpress-site/#post-11384176)
 * Status: not a support question

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
