3

I am trying to create a php website on WordPress for the first time.

When I create a page, it creates a permalink which is of the form http://localhost/?p=123. I don't know if there is a corresponding file.

enter image description here

I've installed insert-php plugin to read php code. It works fine on a static page. But how do I include another php file? I want to include my_utilities which contains all the back-end functions, in login. It has a permalink 'http://localhost/?page_id=45'.

What to do?

include 'http://localhost/?page_id=45' doesn't work.

1
  • the 'http://localhost/?page_id=45' type stuff is there for users to read pages, things you want to use as script should be uploaded to your server and their folder structure path defined in your include function, eg. include('path/to/folder/my_utilities.php); Commented Nov 7, 2014 at 19:07

2 Answers 2

6

Pages you define in WordPress's backend are pages mostly setup for your users to view / read. They, by default, have this URL structure of http://localhost/?p=123 (though this can be changed, but that's a whole different lesson).

To include a script file, upload the file to your folder structure where you have your website then refer to it in your include statement as follows:

include('path/to/folder/my_script.php');

EDIT: You may also want to have a look into WordPress Page Templates:

Pages are one of WordPress's built-in Post Types. You'll probably want most of your website Pages to look about the same. Sometimes, though, you may need a specific Page, or a group of Pages, to display or behave differently. This is easily accomplished with Page Templates.

Sign up to request clarification or add additional context in comments.

2 Comments

Here is a part of my code. Should my_utilities.php file contain [insert_php] tag, <?php tag or none?
It worked. Thank you. It should refer to a real php file not the one with the [insert_php] tag.
5

For exapmle your wordpress file is at

/var/www/html/wp-content/myphpfiles/test.php

To include the test.php file in your wordpress page you have to following.

[insert_php] include('wp-content/myphpfiles/test.php'); [/insert_php]

Thats it.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.