Include wordpress theme in custom php page

I need to include a custom PHP page in Wordpress.

So, I just need to show this custom php page using the Wordpress theme installed on this Wordpress.

It doesn’t mind which theme is inserted, a custom PHP page should be displayed under any theme installed at that moment.

How to do it in Wordpress?

I am new to Wordpress development.

thanks

+4
source share
4 answers

Creating a custom php page that can be viewed in any topic (and the theme is applied) will be much more difficult.

Each Wordpress page invokes certain theme functions for that particular theme, as well as links to files for that theme to generate header files, footers, css, javascript files, etc. On your user page, you will need to plan all these unforeseen circumstances for each topic used.

Here's an alternative solution: enter the PHP code directly into the standard Wordpress page through this plugin http://wordpress.org/extend/plugins/allow-php-in-posts-and-pages/

Meaning: you make a regular Wordpress page, but you can add php to it. When this page is displayed, the correct page template is used, and all links to topics take care of you.

+4
source

You can do this easily with a page template. WordPress allows you to create page templates that can be assigned to a page through the Page Attributes panel in the page editor. These templates are php files inside your themes directory that start with some code (see this page in Codex for more information):

<?php /* Template name: Custom PHP Page */ ?> <?php // begin custom PHP page ?> 

Typically, a template is a variation in a regular theme file (for example, page.php) and calls the get_header () and get_footer () functions and has a loop instance. However, if you just want to use a custom PHP page, you just need to create the desired file in the current themes directory and add the above code to the very top of the file.

To display a custom PHP page on your site, you will need to add a new page through the administration area, and then assign a new page template to this page.

Alternatively, if you want to include a custom PHP page in an existing theme file, use the code:

 <?php include(TEMPLATEPATH . '/includes/file.php'); ?> 

in this case, your custom PHP file will be inside a directory named 'includes' in your current theme directory.

Tim.

+2
source

It is not that difficult. Here is what you need:

As soon as you include the main headline of a wordpress blog, you have access to the entire arsenal of wordpress features, which allows you to get an active theme catalog. Once you get this, just include the subject header and footer.

 // If title is not displayed before loading the header, Wordpress displays "Page not found" as the title echo "<head> <title>Your page title</title> </head>"; // Include the Main Wordpress blog header include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php"; //Now, you need to get the active theme folder, and get a relative path to that folder $homeurl=home_url(); $ddir= get_bloginfo( 'template_directory'); $current_theme_relative_path=substr_replace($ddir, "", 0, strlen($homeurl)); //echo "<br/>The relative path to the currently active theme is ".$current_theme_relative_path; //Once you have the path, include the header and footer, adding your custom php code in between. // Include the specific theme header you need include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/header.php"; // Your custom PHP code STARTS here // Add anything you want to display to the user echo " <h2> Your form has been submitted </h2>"; // END of custom code ?> <?php } // Now end with the theme footer include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/footer.php"; ?> 
+1
source

It was very helpful (even if dated 2011-13)

Also, as a thank you, I use the version I made

useful if your wordpress folder is not in ROOT

PasBin Link - Custom Wordpress PHP Page

just change the value of $ wplocalpath to:

// Path to Wordpress (if wordpress is not in ROOT

// $ wplocalpath = "/ Wordpress1";

0
source

All Articles