0

I have a website where I use [insert_php] to insert php content to my page. What I do is simply use php's include inside insert_php to include my complex php script.

I asked a question a while ago, and got highly criticized for doing it this way and using insert_php. What is the right way to do this?

Let me explain what I have: I wrote a php page with my hands from scratch. This php executes some sophisticated commands on my system and extracts data from my server and displays them. What is the right way to include this php script/page in a wordpress page to display data?

2 Answers 2

1
  1. Duplicate the post.php in your theme folder.

  2. Rename that file as any_name.php

  3. Enter the following code at the top of that file.

< ?php /* Template Name: Any Name */ ?>

  1. Add your php codes to that file.

  2. Go to admin panel -- > Create a new page -- > Select your template and publish the page

2

There are two typical approaches, depending on what you need and consider a page.

First is a whole page page, HTML markup and everything. In this case the proper way is usually to create a template in your theme (or child theme), following template hierarchy and modify it. Another approach would be to use hooks to insert your changes, which is more typical of theme frameworks.

Second is if you just want to add something to content of the page. Which you are doing right now (just in a way that's prone to security issues and such). The dangerous part is having PHP inside your content, but shortcodes are actually good in general.

You can create your custom shortcode via API. It will wrap away access to raw PHP code, but will still allow you to have degree of control over it with shortcode arguments if necessary.

Your Answer

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

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