0

I am working on a application where i only need to get wordpress footer on outside php page i am using below code

<?php require('../wp-blog-header.php'); ?>
<?php wp_footer(); ?>

but it is loading NULL,when i useing below code

<?php require('../wp-blog-header.php'); ?>
<?php get_header(); ?>
<?php wp_footer(); ?>

it loads both header and footer but i want to load only footer please let me know what should i do

Thanks

1 Answers1

0

Refer from this question.

You can use get_footer() function.

<?php

require __DIR__ . '/wp-blog-header.php';

// create false $wp_styles to prevent errors.
$wp_styles = new \stdClass();
$wp_styles->queue = [];

get_footer();

In case that your file is the same location with wp-blog-header.php then use the same path as shown above.

Warning! The result maybe invalid HTML as the elements are closed without open. Example </div> without matched <div>.

Alternative solutions.

  • Use cURL to fetch your home page and then use PHP Dom to grab only specific HTML part. Ideas: 1, 2
  • Use AJAX to fetch your home page and then use JS Dom to grab only specific HTML part. (See reference).

These 2 choices, I can't show the code because each WordPress theme use different HTML elements and styles.

vee
  • 4,506
  • 5
  • 44
  • 81
  • get_footer() returning null – XenBulletins Nov 23 '21 at 18:04
  • if i use get_header() then it works but return both header and footer – XenBulletins Nov 23 '21 at 18:05
  • @XenBulletins Refer from [WP doc](https://developer.wordpress.org/reference/functions/get_footer/) the `get_footer()` function call theme's footer[-xxx].php. If it really is `null` then check your WP theme that footer file render something or not. It is hardly possible to be `null`. My result: the theme's footer was rendered before error messages. – vee Nov 23 '21 at 18:10