I have developed a custom PHP page with filters, add to cart module, music playlist everything. How can i implement it into WordPress? I am a newbie, any help thanks.

My custom PHP work directory structure :

location    : public_html/my_work

website URL : website.com/my_work

Everything is working good, but my WordPress Header and Footer are missing. How to implement my custom development multiple PHP page work into WordPress?

  • Any help to improve my question?
    – Gem
    Oct 12, 2019 at 5:39
  • 2
    you could improve your question by explaining how those diverse customizations tie together and how you want it to interact with WordPress. have you looked into using a shortcode or a template to display your custom page?
    – majick
    Oct 12, 2019 at 7:03
  • ps. I upvoted your question for actually asking how to improve it, which no one ever seems to do and why I responded. :-)
    – majick
    Oct 12, 2019 at 7:04
  • @majick I really appreciated your work.
    – Gem
    Oct 12, 2019 at 7:33
  • Pls check with my updated post.
    – Gem
    Oct 12, 2019 at 7:37

2 Answers 2


You can integrate your PHP file into WordPress with various ways like you can create a plugins and activate plugins and then you get all your PHP file accessible to WP functions.

It's bit dirty but in your case if you wish you add require_once(rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/wp-load.php'); on top of the files or if all files are loaded through index.php add the code on top of the file and after that you can include get_header() and in footer you can write get_footer().

In response to your question in chat for not accessing this in local host is, localhost $_SERVER['DOCUMENT_ROOT'] returns path to localhost/ and your package is accessible on localhost using http://locahost/yoursite You have to modify for localhost or if you test this on server with subdomain you have to modify code like require_once(rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/yoursite/wp-load.php');

  • WordPress has its own constants and functions to get directories like get_template_directory() I would not recommend using any $_SERVER['DOCUMENT_ROOT'] and general PHP stuff like that but rather work with what WP offers. Oct 15, 2019 at 11:48
  • @NextGenThemes Thanks for your update and DOWN VOTE but can you tell me until WP accessible in custom PHP file how could any one write get_template_directory() function without getting an error undefined function?
    – Vantiya
    Oct 15, 2019 at 13:13
  • NO problem, you of course are supposed to fully load WordPress first. But you both seem not to be up for what is best but rather what works first. You should be happy he accepted your bad answer. You are supposed to use get_header() inside a theme and when you are loading a theme correctly you have access to all the WP functions (excluding only admin code). I am not sure what you are doing but its wrong, and pretty much proves my point that you should not start with using $_SERVER['DOCUMENT_ROOT'] and the likes at all when using WP. Oct 16, 2019 at 11:01

Abandon your old structure! Possibly move it into a plugin. You are entering a new and complicated world and it looks like you need to learn about it. Better learn how WP works instead of trying to make it bend to what you have in mind.

If you want dynamic things happening from existing php code the simplest way to get that into WP are shortcodes. You make your code return what you want to output on a page/post and then put that shortcode in where your php generated stuff should be.

Plugin Name: BestPluginEva
Plugin URI:
Version: 0.0.1
Author: You
Author URI:
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl.html
namespace You\YourStuff;

add_action( 'init', __NAMESPACE__ . '\register_shortcode' ); 

function register_shortcode() {
    add_shortcode( 'old_content_output', __NAMESPACE__ . '\old_content_shortcode' );

function old_content_shortcode( $atts = [], $content = null ) {

    $shortcode_html_output = your_old_content();

    // always return never echo or break out of php into HTML
    return $shortcode_html_output;

This can get your started. Then put [old_content_output] into a page to get your old php code to output it there.

  • My application like => webslesson.info/2018/08/…, more than one PHP page, index.php is the main file, how can i proceed with your guide?
    – Gem
    Oct 15, 2019 at 4:43
  • If pages are loaded with AJAX but switch by a #url-hash you could still make it work in a single WordPress page. But again: I feel you are going to fast and possibly doing it wrong. You can not just move something like that into WP. You need to learn how WP actually works and probably completely redo that you got. For example that tut uses mysql and jquery. WordPress has its own API for MySql that you need to learn how to use and create tables in a secure way. Then you need to use the jQuery version that WP comes with and learn how the wp_enqueue system works ... Oct 15, 2019 at 5:07
  • What you are asking for can not just simply answered with a one and only working solution. There is also the WP REST API that you would ideally use to make AJAX requests for data stored in the WP mysql database ... Oct 15, 2019 at 5:10
  • Successfully integrated header & footer. code : require_once(rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/wp-load.php'); and using get_header(); & get_footer(); now everything alright.
    – Gem
    Oct 15, 2019 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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