'i want condition active page/or open post page, title not show in sidebar

i want condition active page/or open post page, title not show in sidebar

<?php  
    $the_query = new WP_Query( array('post_type' => 'courses')); ?>               

<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

    <div class="other-courses-text">
        <a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a>
    </div>

    <?php endwhile; 
        wp_reset_postdata();  
    else : ?>
    <div class="news-main-box">
        <p><?php __('No News'); ?></p>
    </div>
<?php endif; ?>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source