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

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.

Leave a Comment