admin管理员组文章数量:1279207
I cannot believe that this question has not already been answered, but the search does not come up with anything. If it has already been answered, please point me in the right direction!
There are many options for "blank" or "starter" themes and plugins, but there seem to be no resources on how to completely remove the default header and footer without installing or modifying themes. Surely there is a simple way to do this within functions.php, just as you can remove the admin bar without a plugin.
I cannot believe that this question has not already been answered, but the search does not come up with anything. If it has already been answered, please point me in the right direction!
There are many options for "blank" or "starter" themes and plugins, but there seem to be no resources on how to completely remove the default header and footer without installing or modifying themes. Surely there is a simple way to do this within functions.php, just as you can remove the admin bar without a plugin.
Share Improve this question asked Jun 10, 2019 at 6:05 AnonymousAnonymous 231 silver badge5 bronze badges 4- 3 the reason there is no one "right" answer is because it depends on the specific theme. – majick Commented Jun 10, 2019 at 6:08
- 4 ie. there is no such thing as a "default" header or footer in WordPress, only those that are output by the theme used. – majick Commented Jun 10, 2019 at 6:10
- 1 you can search for tutorials on how to do this with twenty nineteen. otherwise, finding a good theme that you want to continue using (and that you can do this easily with as one requirement and elementor support as another etc etc.) is a search definitely worth undertaking. just not wanting to install a different theme from the outset is actually more of a waste of time than just finding and consistently using what suits your needs. – majick Commented Jun 10, 2019 at 7:14
- so far as I know only Oxygen eliminates the need for a theme like this, so maybe worth taking a look at that... such an approach has it's pros and cons of course. – majick Commented Jun 10, 2019 at 14:19
2 Answers
Reset to default 0The reason you're not finding a quick fix is that there isn't a consistent way to hide header and footer content across all templates, across all themes. Also, even builders like Elementor require the ability to enqueue their own CSS and JS. If you completely remove the header and footer, you will almost always also be completely removing the necessary hooks, wp_head()
and wp_footer()
. It's also a more common use case to include a sitewide header and footer, rather than trying to manage that sort of thing on a page-by-page basis.
If you truly don't need these sitewide elements, it would probably be simplest to build your own theme. All you need are 3 files.
File #1: style.css
/*
Theme Name: WPSE Barebones
*/
You don't have to add any actual styles, but this comment will make WP recognize your theme.
File #2: index.php
<html>
<head>
<?php wp_head(); ?>
</head>
<body>
<main>
<?php if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_content();
endwhile;
endif; ?>
</main>
<?php wp_footer(); ?>
</body>
</html>
The <main>
tag is possibly optional, but it's not a bad idea to have one containing HTML element for Elementor.
Okay, last file:
File #3: functions.php
<?php
function wpse_support_title_tags() {
add_theme_support( 'title-tag' );
}
add_action( 'after_setup_theme', 'wpse_support_title_tags' );
?>
This allows WordPress to set a <title>
tag inside the <head>
(due to the call to wp_head()
) so each page has an automatic title.
into page.php file or , every page you need them.
remove_action('generate_header', 'generate_construct_header');
本文标签: How do you completely remove the default header and footer using functionsphp
版权声明:本文标题:How do you completely remove the default header and footer using functions.php? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741272261a2369522.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论