How to hide sidebar on custom single post template for custom post type?

As suggested in this Forum, I am using “Custom Post Type UI” plugin to create a custom post type for “Press Releases”. Also as suggested, I have created copies of both “wp-single.php” and “wp-index.php” with the names “wp-single-press-release.php” and “wp-index-press-release.php” in the child theme folder.

Something must be missing in my understanding of the hierarchy because it seems like the templates are not really cancelling out the blog settings. The the single post have a sidebar.

The single post page to be full width with no sidebar.

Any guidance is greatly appreciated, this is a link for development site and specifically the press releases page.

Here is the code setup for “wp-single-press-release.php”:


<?php

// =============================================================================
// VIEWS/INTEGRITY/WP-SINGLE-PRESS-RELEASE.PHP
// -----------------------------------------------------------------------------
// Single post output for Integrity.
// =============================================================================

$fullwidth = get_post_meta( get_the_ID(), '_x_post_layout', true );

get_header();

?>

  
<?php while ( have_posts() ) : the_post(); ?> <?php x_get_view( 'integrity', 'content', get_post_format() ); ?> <?php x_get_view( 'global', '_comments-template' ); ?> <?php endwhile; ?>
<?php if ( $fullwidth != 'on' ) : ?> <?php get_sidebar(); ?> <?php endif; ?>
<?php get_footer(); ?>

Hi @MLTCreative,

Thank you for reaching out to us. If you want to exclude the sidebar from your single custom post type then you should remove the following lines from the wp-single-press-release.php file:

<?php if ( $fullwidth != 'on' ) : ?>
      <?php get_sidebar(); ?>
    <?php endif; ?>

Hope this helps!

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