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 | Show 4 more comments2 Answers
Reset to default 9Here 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 );
本文标签:
版权声明:本文标题:Echoing Elementor page content in template, but it doesn't get styles and some widgets are missing 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736655117a1946234.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
functions.php
? Since you havewp_head()
here they should come through if they are. If not, you should remove them from being directly added toheader.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:27style.css
to figure out where it's coming from. If it's added properly you should see a call towp_enqueue_style
infunctions.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