In a plugin I want to display a specific page without redirecting (and thus without changing the URL) like the plugin / does. I can capture 404s and redirect them, but I want the URL to stay the same when I show a custom page.
// A. this only displays the content and the not the header, footer, or title.
$post = get_page_by_path('/some-page/');
$content = apply_filters('the_content', $post->post_content);
echo $content;
...
// B. This only displays the page template, but doesn't include the content.
$template = get_template_part('page');
echo $template;
...
// C. A combination of the two doesn't include the sidebar or the or the page title.
$template = get_template_part('header', 'custom-404-page');
echo $template;
$post = get_page_by_path('/custom-page/');
$content = apply_filters('the_content', $post->post_content);
echo $content;
$template = get_template_part('footer', 'custom-404-page');
echo $template;
... I also tried:
// D.
global $post;
$post = get_page_by_path('/custom-404-page/');
setup_postdata($post);
$template = get_template_part('page');
echo $template;
but the content of the page still doesn't appear in the basic page template.
thanks