Echoing Elementor page content in template, but it doesn’t get styles and some widgets are missing

I built a page with Elementor, and I want to use it as my home page. When I use a static home page with my theme, it still gets wrapped with the header, footer, and content container, which I don’t want in this case.

I’ve built a simple front-page.php template to try to just output the contents of this page.

<!DOCTYPE html>
<html <?php language_attributes(); ?> class="no-js no-svg">
    <head>
        <meta charset="<?php bloginfo( 'charset' ); ?>">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="profile" href="http://gmpg.org/xfn/11">
        <?php wp_head(); ?>
    </head>

    <body <?php body_class(); ?>>
<?php
$page = get_page_by_path( 'home' );
$content = apply_filters('the_content', $page->post_content); 
echo $content;

get_footer();
?>
  </body>

  <?php wp_footer(); ?>

This works to output the content, but I don’t get the styles and my posts widgets are MIA. How can I modify this template to also get the styles and so that all the widgets will be present?

2 s
2

Here is the way,

$contentElementor = "";

if (class_exists("\\Elementor\\Plugin")) {
    $post_ID = 124;
    $pluginElementor = \Elementor\Plugin::instance();
    $contentElementor = $pluginElementor->frontend->get_builder_content($post_ID);
}

echo $contentElementor;

Leave a Comment