0

I have a WordPress Child Theme and I have added a php file to this child theme. Also I want to use WordPress functions in this file ( I want to show header, menu and footer )

So I try

<?php

$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once( $parse_uri[0] . 'wp-load.php' );

?> 

Also I try to add header and footer

<?php get_header();?>

//my content

<?php get_footer();

But it seems it can't load all css/js files and page have bad styling.

1
  • 3
    Use the PHP file as a template file, then you have access to all WP functions automatically.
    – fuxia
    Commented Sep 6, 2016 at 13:00

1 Answer 1

3

There are two things to do to make this work. First, you have to turn your php file into a template that can be recognized by WordPress. This is simply done by adding the following to the top of your file:

<?php /* Template Name: WPSE Example Template */ ?>

The second thing is, you must make sure this file is not called directly, but through WordPress, so functions like get_header are recognized. This you do by making a page in WP. You can leave everything blank, including the title. Just make sure that you assign your template as the one to be used by this page. Use the permalink generated when you save the page to display it.

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.