Template Condition: Exclude by Page Template

This is a How to and a Possible feature request. But I have a template I built in bricks that turns off the header and footer. That’s fine. However, I want users to select the template from the Page Template selection UI in the editor. I have taken my template and placed it within a WP Page Template like so.

<?php
/*
Template Name: Squeeze Page
*/

get_header(); // This function call includes the header template.

?>

<main id="main" class="site-main" role="main">
    <!-- Here we output the shortcode [bricks_template id="788"] -->
    <?php echo do_shortcode('[bricks_template id="788"]'); ?>
</main><!-- #main -->

<?php
get_sidebar();
get_footer(); 
?>

This works fine except that the header and footer are included and if I comment out the header and footer, the site output is borked, obviously.

The template conditions do not allow for page template selection for header/footer.
How do I get around this? Is there a different way to call the header and footer such that a) it doesn’t load and b) doesn’t mess up the output of the page?

1 Like

You can always write a condition within the template’s PHP file without using conditions within Bricks itself. Copy the header/footer.php template to your child theme and do something like:

<?php

namespace Bricks;

if (!is_page_template('page-templates/template-squeeze-page.php')) {

do_action( 'bricks_before_footer' );

do_action( 'render_footer' );

do_action( 'bricks_after_footer' );

}

do_action( 'bricks_after_site_wrapper' );

wp_footer();

echo '</body>';

echo '</html>';
1 Like

Hey, is this as simple as loading just wp_head() instead of get_header() [this loads bricks parent header.php] ?

Or, create your own header.php… such as header-squeeze.php

You then call it with get_header('squeeze'), which would have your custom code in there, with required <head> and wp_head() for displaying normal WordPress assets etc.

If you look @ parent bricks header.php it currently looks like this (Bricks 1.9.7.1):

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php do_action( 'bricks_meta_tags' ); ?>
<?php wp_head(); ?>
</head>

The <?php do_action( 'bricks_meta_tags' ); ?> is the only thing they add (plus their hooks… [which i stripped for focusing on wp_head()]… but these are what you do not want which are displaying the header?)

Here is get_header() doc.

Hope I did not misunderstand your question…

It turns out that YES it is!! I knew I was over-engineering my approach. Just calling wp_head(); and wp_footer(); is exactly what I wanted to do. This is why I ask the questions!!

Thank you for your input.

Haha right on!

Something I’ve noticed, if you just call wp_head(), you may experience “Quirks Mode” where the CSS is not styled properly on all devices… because the <!DOCTYPE html> is not called with just wp_head()!!!

So creating your own header-YOURNAME.php like I showed above, and making sure it has wp_head() in there can usually prevent that “Quirks Mode”…

You can see it has <meta name="viewport" and a bunch of other mumbo jumbo :slight_smile: … common in most header.php stuff I’ve seen when designing my own custom stuff

Again, you simply call it with get_header('YOURNAME'); (from my header-YOURNAME.php example in this message)