Site logo

[Resolved] Remove Category Page Description From Category Subpages

Home Forums Support [Resolved] Remove Category Page Description From Category Subpages

Home Forums Support Remove Category Page Description From Category Subpages

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #211207
    Yomi

    Hi Tom,

    The theme shows category description in the category archive page. I want the description to be shown on the MAIN page only of the category but not on the other category sub pages. how can I stop sub-pages from showing the description.

    I have found some code on the link below but cannot figure how to effectively use it

    Please advice on the best way to get the category description to show only on the main page of the category

    Below is the link to the codes I got

    removing category description from category subpages

    Kind regards

    #211263
    Tom
    Lead Developer
    Lead Developer

    Currently, GP just uses the default WordPress way of displaying the category description, which adds it to every page (to describe the posts below).

    If you need to change it, you would need to copy the archive.php file and add it to your child theme.

    Then you would need to find the category_description() function, and replace it with something like this:

    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if ($page == 1) {
        echo category_description();
    }

    Trouble with that is you won’t get updates made to the archives.php template anymore, as it will only listen to your child theme file.

    #211339
    Yomi

    Hi Tom,

    Thanks for that.

    Now I have copied the archive.php file over but the problem is where do i find the “category_description() function”?

    I have looked in the archive.php but cannot find anything like that.

    Below is what I have in the archive.php file

    
    
    <?php
    /**
     * The template for displaying Archive pages.
     *
     * Learn more: http://codex.wordpress.org/Template_Hierarchy
     *
     * @package GeneratePress
     */
    
    get_header(); ?>
    
    	<section id="primary" <?php generate_content_class(); ?>>
    		<main id="main" <?php generate_main_class(); ?>>
    		<?php do_action('generate_before_main_content'); ?>
    		<?php if ( have_posts() ) : ?>
    
    			<?php do_action( 'generate_archive_title' ); ?>
    			
    			
    			<?php /* Start the Loop */ ?>
    						
    			
    			<?php while ( have_posts() ) : the_post(); ?>
    
    				<?php
    					/* Include the Post-Format-specific template for the content.
    					 * If you want to override this in a child theme, then include a file
    					 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    					 */
    					get_template_part( 'content', get_post_format() );
    				?>
    
    			<?php endwhile; ?>
    
    			<?php generate_content_nav( 'nav-below' ); ?>
    
    		<?php else : ?>
    		
    		<?php get_template_part( 'no-results', 'archive' ); ?>
    
    		<?php endif; ?>
    		<?php do_action('generate_after_main_content'); ?>
    		</main><!-- #main -->
    	</section><!-- #primary -->
    
    <?php 
    do_action('generate_sidebars');
    get_footer();
    
    
    #211353
    Tom
    Lead Developer
    Lead Developer

    Sorry about that – I forgot that I moved the archive titles into a function: https://gist.github.com/generatepress/fe5309693719d138dbcf84381eb9a6b3

    You’ll want to adjust the $term_description code.

    You can add that code as a function: https://generatepress.com/knowledgebase/adding-php-functions/

    #211370
    Yomi

    Still need some additional help Tom…

    so far here is what i have done

    I am using a child theme

    I have copied over the archives.php file into my child theme

    From what I understand now… I have to place a code in my functions file to achieve my goal

    …. what code should i place directly in the functions file of my child theme?

    Please help with the code

    #211376
    Tom
    Lead Developer
    Lead Developer

    You no longer need archive.php – you can delete that file from your child theme.

    Give this function a try: https://gist.github.com/generatepress/cc2d8b578c8c3706dcefe68234ca5c9f

    #211386
    Yomi

    Excellent!!! 🙂

    Absolutely love it….

    Works like a charm once I removed the endif; at the end of the code

    Many thanks

    #211470
    Tom
    Lead Developer
    Lead Developer

    That endif; should be essential.. It should actually crash completely without it.

    #241960
    Janet Davis

    Tom,

    Please help…
    I too only want the category description on the first page of the category.
    I used the above code from

    https://gist.github.com/generatepress/cc2d8b578c8c3706dcefe68234ca5c9f

    as you wrote it.
    I’m using code snippets plugin.

    The catalog description still shows on the category sub pages.

    Thank you
    Jan

    #241983
    Tom
    Lead Developer
    Lead Developer

    Interesting, that code should work.

    Is your code snippet activated?

    #241990
    Janet Davis

    Is seems to be. I’m using 2 other snippets that are working.

    Here is page 2 of the category
    https://everydayhomesteading.com/category/raising-livestock/irish-dexter-cattle/meet-our-dexters/page/2/
    thank you
    Jan

    #242066
    Tom
    Lead Developer
    Lead Developer

    Hmm, I just tried it myself and it is indeed working.

    One thing you can try is this CSS instead:

    .paged .taxonomy-description {
        display: none;
    }
    #242072
    Janet Davis

    Tom,

    THank you that worked like a charm!

    Why use CSS over the snippet coding or vice versus?
    Jan

    #242088
    Tom
    Lead Developer
    Lead Developer

    The CSS just hides it, while the PHP removes it completely from the page.

    #819610
    Dmitry Bychenko

    Thanks, Tom,

    css works good, but there is a gap between Page Title and first post on Archive page.

    What php to use to remove category descriptions from all Archive page, including the first page of the category?

Viewing 15 posts - 1 through 15 (of 21 total)
  • You must be logged in to reply to this topic.