Search code examples
phpwordpressif-statementsidebar

Removing sidebar from categories page


I'm trying to remove the sidebar from my archive.php category page in WordPress. The problem is that the sidebar is included in the footer file, so I need to create a conditional statement to detect what pages are category pages. The if statement in the footer.php file reads:

<?php if(!is_page_template('page-full.php') && (basename($_SERVER['SCRIPT_FILENAME'])!='wp-signup.php')) : ?>
</div><!-- end content -->
    <?php get_sidebar(); ?>
<?php endif; ?>

I tried to add if(!is_category()) to the statement (shown bellow), but it seems to break the whole statement. Am I doing something wrong here?

<?php if(!is_category() || (!is_page_template('page-full.php') && (basename($_SERVER['SCRIPT_FILENAME'])!='wp-signup.php')) : ?>
</div><!-- end content -->
    <?php get_sidebar(); ?>
<?php endif; ?>

Solution

  • You may try this (don't show sidebar on category and single page, or/|| won't work)

    <?php if(!is_category() && !is_single() ) : ?>
        </div><!-- end content -->
        <?php get_sidebar(); ?>
    <?php endif; ?>
    

    This will show sidebar if neither category nor single page.