0

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.

  • 3
    the reason there is no one "right" answer is because it depends on the specific theme. – majick Jun 10 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 Jun 10 at 6:10
  • I'm asking if there is a way to quickly disable those from outputting anything from within functions.php instead of having to make a custom theme the second you install Wordpress. For testing purposes, let's say we're using the default Twenty Nineteen theme. – Anonymous Jun 10 at 6:57
  • Otherwise there is no way for a page builder such as Elementor to start with an actual blank canvas. – Anonymous Jun 10 at 7:03
  • 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 Jun 10 at 7:14
0

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.

  • That's awesome! Thank you so much for sharing this. – Anonymous Jun 10 at 16:00
  • Perhaps you're right in that I should stop trying to remove those functions altogether. The problem I'm having is that wp_head() seems to inject a lot of unnecessary stuff into the header. I've had to install several plugins just to remove some of it. I've been doing a lot of research on how to reduce the overhead that WordPress generates, but almost all of the commands seem to no longer work. In the past one could just add a few lines like remove_action('wp_head', 'wp_generator') to functions.php, but it seems that they no longer work for some reason. – Anonymous Jun 10 at 16:06
  • If you don't have wp_head(), Elementor itself won't have a hook to include the required JS and CSS. Keep looking into functions to remove the extra data - that remove_action works for me with WP 5.2 - and if you run into any CSS or JS that plugins are adding and you need to remove, find out what they're called when they're enqueued, and you can dequeue and deregister them to keep them out of the rendered code. – WebElaine Jun 10 at 20:36
  • You may want to double-check whether your host has caching enabled, or whether your functions may need a priority added to get them to fire after other code runs. – WebElaine Jun 10 at 20:37
  • If I comment out actions in default-filters.php, it works, but trying to remove the same actions in functions.php has no effect. What priority should I assign to override them? – Anonymous Jun 11 at 1:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.