How to call X header and footer from code

In previous versions of X, I used to be able to call get_header() and get_footer() to build an entire page directly from a custom plugin, very simply displaying the header, nav and footer around my plugin-generated HTML.

In the latest version, those functions run but they aren’t pulling in the X-specific code, so the page appears without any visible header or footer.

I have tried combinations of x_get_view() calls to try to produce the same output, but I’m missing some piece of the puzzle to get into the X stack.

I can get started by calling x_get_view('global', '_header') which will produce a header that’s pretty close to correct.

But then if I try to call x_get_view('global', '_navbar') I run into undefined function errors, such as “Call to undefined function x_get_navbar_positioning()”

Do methods exist to call the X header and footer through code?

Hi There,

Please try to use this line:

<?php get_header(); ?>```
For guidance, please check this template: **\wp-content\themes\x\framework\views\integrity\ wp-index.php**

Hope this helps.

That’s exactly what I used to be able to do. I could build an entire web page like this:

get_header();
echo $output; //as generated by custom plugin
get_footer();
exit();

Unfortunately, using those get_header() and get_footer() calls from a custom plugin is somehow outside of the X theme’s context, so it’s not pulling in any visible content for the header and footer - even though the headers and footers display fine from an actual WordPress page.

I can’t figure out how to properly reconstruct X’s stack of function calls and includes to properly get the header and footer. As I said in my original message, attempts to use x_get_view() calls lead to undefined function errors.

What am I missing? Thanks!

Hello There,

get_header() and get_footer() call should work. Please check out the contents of the page.php. It calls for the x_get_view() function.

<?php

// =============================================================================
// PAGE.PHP
// -----------------------------------------------------------------------------
// Handles output of individual pages.
//
// Content is output based on which Stack has been selected in the Customizer.
// To view and/or edit the markup of your Stack's pages, first go to "views"
// inside the "framework" subdirectory. Once inside, find your Stack's folder
// and look for a file called "wp-page.php," where you'll be able to find the
// appropriate output.
// =============================================================================

?>

<?php x_get_view( x_get_stack(), 'wp', 'page' ); ?>

In your child theme, you should have make sure that the template you are calling is there in one of the stack folders or else nothing will happen. As an example, in integrity folder wp-content/themes/x-child/framework/views/integrity/, you have wp-page.php file and its contents is like this:

<?php

// =============================================================================
// VIEWS/INTEGRITY/WP-PAGE.PHP
// -----------------------------------------------------------------------------
// Single page output for Integrity.
// =============================================================================

?>

<?php get_header(); ?>

  <div class="x-container max width offset">
    <div class="<?php x_main_content_class(); ?>" role="main">

      <?php while ( have_posts() ) : the_post(); ?>
        <?php x_get_view( 'integrity', 'content', 'page' ); ?>
        <?php x_get_view( 'global', '_comments-template' ); ?>
      <?php endwhile; ?>

    </div>

    <?php get_sidebar(); ?>

  </div>

<?php get_footer(); ?>

It is clearly using the get_header() and get_footer() function call.

Hope this helps.

It did not directly help, but after fumbling with it for a few days, it did help me stumble upon the solution.

My custom function in my custom plugin was attached to the template_redirect action, but was firing before the legacy header and footer. The x_legacy_modes method is being called with a priority of 25. So I just made sure my method had a lower priority and was fired after the X stack had been set up.

add_action( 'template_redirect', 'my_custom_function_name' , 999 );

Glad you figured it out,

Cheers!