1

I've created a project that is almost all PHP/HTML, except for 5 lines of ajax/javascript in one page. It's been approved but it needs to be part of a wordpress site on a subdomain. I'm familiar with importing a MySQL database and setting up a user for that, and I'm also familiar with putting the db credentials in the wp-config.php file for the main site database.

I have a plugin that allows for save insertion of PHP into pages/posts, but I really don't know the best way to do this. I have 6 or 7 pages of php and one database with 7 tables.

Is there anyone familiar with the best way to go about this? Everything works perfectly on my local server, I just need it to work correctly via wordpress.

5
  • is your project just one page or multiple pages?
    – rudtek
    Apr 13, 2017 at 15:38
  • it is multiple pages, actually 7 php pages with Html mixed in for tables and forms
    – H.Norman
    Apr 13, 2017 at 15:44
  • Sounds like it might be best to create a custom Page Template for each variation of PHP. That way you can include html/editor type content editable in the WP admin, but your PHP will be called through the template selected for that particular page.
    – WebElaine
    Apr 13, 2017 at 15:49
  • Is there perhaps a tutorial on this specifically? I've only ever worked with local PHP, or wordpress with themes but never a hybrid of the two. This site already uses a theme but I just need to add on to it
    – H.Norman
    Apr 13, 2017 at 16:13
  • Plugins that allow saving of PHP in the database and executing it on the frontend are horrifyingly insecure and should be avoided at all costs. This is what page templates and shortcodes are for
    – Tom J Nowell
    Apr 13, 2017 at 16:19

1 Answer 1

1

There are 2 ways you could do this.

The first would be by creating a separate template for each of the pages you want. This is if you're going to change a lot of different aspects of the page for each of the 7 pages.

A page template will include the header, footer, and sidebar calls for you. You'll be able to insert the php in the main body container that is created by the template.

The best way to start creating a page template is by copying one from your current theme. Likely your theme is already using one and all you have to do is pull one from the main theme directory and copy it to your child theme directory. Then look for the main container and put your php coding there.

Make sure to change the template name to your own in the top of this file. Now, when you create a new page in your wp dashboard, simply choose the template from the template drop down on the left, hit publish, and your content will be there.

The 2nd way would be to add add your content as functions to be called later. (either in your functions.php or an included php file you create) and call the functions in your page. If you do this, it provides the option of creating a shortcode that you can call on any page, or directly call the function dynamically through conditional calls on a template page.

As for the javascript you'll likely want to enqueue it in wordpress fashion if it's not already included properly.

2
  • I think I understand what you mean here. If I see what you're saying, my code really shouldn't change at all but it's a matter of certain PHP pages calling others. So I don't know what might be best, but we already use a wordpress theme where I've done some custom functions in functions.php so I"m thinking it might be best to do page templates. Is there a place where I can get some good starting info on how to do that?
    – H.Norman
    Apr 17, 2017 at 13:37
  • You've got the idea. If the code isn't ever going to change and is relevant to only one page, I would actually run it in a template. Both ways work though, and you could try experimenting with each so you're ready for the next project.
    – rudtek
    Apr 17, 2017 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.