How do you completely remove the default header and footer using functions.php?

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.

Topic footer headers functions Wordpress

Category Web



into page.php file or , every page you need them.

    remove_action('generate_header', 'generate_construct_header');

The 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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.