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.

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 2

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.

3
  • 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
    Commented Jun 10, 2019 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
    Commented Jun 10, 2019 at 20:37
  • I have tried adding remove_action to functions.php matching the priority of the original add_action in default-filters.php, but it still doesn't work.
    – Anonymous
    Commented Jun 14, 2019 at 3:09
0

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

    remove_action('generate_header', 'generate_construct_header');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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