admin管理员组

文章数量:1125037

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="">
        <?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?

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?

Share Improve this question asked Jul 5, 2018 at 15:08 raddevonraddevon 2134 silver badges12 bronze badges 9
  • 1 In your theme, are the styles actually enqueued through functions.php? Since you have wp_head() here they should come through if they are. If not, you should remove them from being directly added to header.php and instead enqueue, so they can also appear here. As far as widgets, it depends on where your widgetized area is. Check your other template files and see - there is probably a sidebar (even if visually it's not a sidebar, WP calls it a sidebar) which you'll need to call in order to display widgets here as well. – WebElaine Commented Jul 5, 2018 at 15:27
  • @WebElaine I'll check where the styles are enqueue. Thanks! On the widgets, I wasn't at all clear about what I was talking about. I'm referring to an Elementor widget rather than a WordPress widget here. I have a posts list on the page using Elementor's posts widget – raddevon Commented Jul 5, 2018 at 15:31
  • 1 Search your theme files for style.css to figure out where it's coming from. If it's added properly you should see a call to wp_enqueue_style in functions.php. If it's just hard-coded as a <link rel="stylesheet"> somewhere, that's the problem with the styles. It's also worth inspecting the homepage itself to see whether there is any reference to the styles - it could be the stylesheet is loading but somehow you're missing a body class or something critical. Or could be the stylesheet tries to load but it's the wrong path. – WebElaine Commented Jul 5, 2018 at 15:45
  • 1 Sounds like you need to contact Elementor's authors to figure out the best way to meet your goals. – WebElaine Commented Jul 5, 2018 at 17:02
  • 1 You can change the elementor style output to be an inline in the elementor settings->advanced – Shibi Commented Jul 5, 2018 at 18:49
 |  Show 4 more comments

2 Answers 2

Reset to default 9

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;

get_builder_content is an internal method, please use get_builder_content_for_display().

$frontend = new \Elementor\Frontend();
$page_id  = 100;

echo $frontend->get_builder_content_for_display( $page_id, $with_css = true );

本文标签: