Remove footer in CPT

Hello guys,

We have created a custom post type and we’d like to remove the footer entirely.

The template we want to reproduce is Icon’s Template-Blank-5.php with no-container, a header and no footer.

<?php

// =============================================================================
// VIEWS/ICON/TEMPLATE-BLANK-5.PHP (No Container | Header, No Footer)
// -----------------------------------------------------------------------------
// A blank page for creating unique layouts.
// =============================================================================

get_header();

?>

  <div class="x-main full" role="main">

    <?php while ( have_posts() ) : the_post(); ?>

      <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <div class="entry-wrap">
          <?php x_get_view( 'global', '_content', 'the-content' ); ?>
        </div>
      </article>

    <?php endwhile; ?>

  </div>

  <?php x_get_view( 'icon', '_template-blank-sidebar' ); ?>

<?php

if ( apply_filters( 'x_legacy_cranium_footers', true ) ) {
  x_get_view( 'global', '_footer' );
} else {
  get_footer();
}

?>

Assuming our CPT slug is “story” we have added in our child-theme a file “single-story.php” where we have added the following code:

<?php
// =============================================================================
// VIEWS/ICON/WP-SINGLE.PHP
// -----------------------------------------------------------------------------
// Single post output for Icon.
// =============================================================================
get_header();
?>

<div class="x-main full" role="main">
	<?php while ( have_posts() ) : the_post(); ?>
		<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
			<div class="entry-wrap" style="padding:0;border-bottom:0;">
					<?php do_action( 'x_before_the_content_begin' ); ?>
					<div class="entry-content content" style="margin:0;padding:0;">
							<?php do_action( 'x_after_the_content_begin' ); ?>
								<?php the_content(); ?>
							<?php do_action( 'x_before_the_content_end' ); ?>
					</div>
					<?php do_action( 'x_after_the_content_end' ); ?>
				</div>
		</article>
	<?php endwhile; ?>
</div>

<?php 
if ( apply_filters( 'x_legacy_cranium_footers', true ) ) {
	x_get_view( 'global', '_footer' );
} else {
	get_footer();
}
?>

However we keep having the default global footer added in our CPT.

If I remove get_footer(); the page is broken (admin bar doesn’t display).

Am I missing something?

Thank you!

Hi @thisisbbc,

Please try to replace this part:

<?php 
if ( apply_filters( 'x_legacy_cranium_footers', true ) ) {
	x_get_view( 'global', '_footer' );
} else {
	get_footer();
}
?>

With this:

    <?php do_action( 'x_before_site_end' ); ?>

    </div> <!-- END .x-site -->

    <?php do_action( 'x_after_site_end' ); ?>

  </div> <!-- END .x-root -->

<?php wp_footer(); ?>

</body>
</html>

Hope this helps.

Hello Lely,

Thank you for the provided snippet.

Unfortunately the footer is still displayed. Here’s the full code for the “single-story.php” template we currently use:

<?php
// =============================================================================
// VIEWS/ICON/WP-SINGLE.PHP
// -----------------------------------------------------------------------------
// Single post output for Icon.
// =============================================================================
get_header();
?>

<div class="x-main full test" role="main">
	<?php while ( have_posts() ) : the_post(); ?>
		<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
			<div class="entry-wrap" style="padding:0;border-bottom:0;">
					<?php do_action( 'x_before_the_content_begin' ); ?>
					<div class="entry-content content" style="margin:0;padding:0;">
							<?php do_action( 'x_after_the_content_begin' ); ?>
								<?php the_content(); ?>
							<?php do_action( 'x_before_the_content_end' ); ?>
					</div>
					<?php do_action( 'x_after_the_content_end' ); ?>
				</div>
		</article>
	<?php endwhile; ?>
</div>

<?php do_action( 'x_before_site_end' ); ?>
	</div> <!-- END .x-site -->
<?php do_action( 'x_after_site_end' ); ?>
	</div> <!-- END .x-root -->
<?php wp_footer(); ?>
	</body>
</html>

Waiting for your feedback.

All best,
B

Hey B,

The suggestion by Lely would work if you don’t have a Global Footer. I believe that’s unavoidable though so follow the suggestion below.

Below is a sample code that must be added in the functions.php of your child theme to remove both the Classic Footer and Pro Footer in the Single Post. This can be tweaked for Custom Post Types.

add_action( 'template_redirect', 'remove_footer_in_single_cpt' );

function remove_footer_in_single_cpt() {
    if ( is_singular( 'post' ) ) {
        add_filter( 'x_output_footer', false  );
        add_filter( 'x_legacy_cranium_footers', false  );
    }
}

Take note of the condition is_singular( 'post' ). Change post to your custom post type like is_singular( 'story' ). For more details about is_singular, please read this documentation: https://developer.wordpress.org/reference/functions/is_singular/

That code should work as long as wp_footer() is present in your template. Both your previous setup (based on Page Template 5) and Lely’s suggestion still has the wp_footer so the Footer is still being outputted.

The only difference is, if get_footer is used and you don’t have a Footer assigned as Global, the Classic Footer will be displayed. If wp_footer is used and you still don’t have a Global Footer or a footer assigned to your custom post type, no footer will be outputted.

Hope that helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.