Archived topic
Remove Category Page Description From Category Subpages
20 replies · Started by Yomi on July 19, 2016
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
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.
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();
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/
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
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
Excellent!!! :-)
Absolutely love it....
Works like a charm once I removed the endif; at the end of the code
Many thanks
That endif; should be essential.. It should actually crash completely without it.
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
Interesting, that code should work.
Is your code snippet activated?
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
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;
}
Tom,
THank you that worked like a charm!
Why use CSS over the snippet coding or vice versus?
Jan
The CSS just hides it, while the PHP removes it completely from the page.
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?