最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

templates - How to implement my custom development multiple PHP page work into Wordpress?

programmeradmin2浏览0评论

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/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?

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/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?

Share Improve this question edited Oct 15, 2019 at 8:48 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Oct 12, 2019 at 4:57 GemGem 276 bronze badges 16
  • Any help to improve my question? – Gem Commented 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 Commented 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 Commented Oct 12, 2019 at 7:04
  • @majick I really appreciated your work. – Gem Commented Oct 12, 2019 at 7:33
  • Pls check with my updated post. – Gem Commented Oct 12, 2019 at 7:37
 |  Show 11 more comments

2 Answers 2

Reset to default -1 +100

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');

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.

<?php
/*
Plugin Name: BestPluginEva
Plugin URI:
Description:
Version: 0.0.1
Author: You
Author URI:
License: GPLv3
License URI: http://www.gnu/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.

发布评论

评论列表(0)

  1. 暂无评论