Site logo

Archived topic

Category description below category posts

5 replies · Started by ETO on March 15, 2019

Viewing posts 1–6 of 6

Hello,
In the category pages, there appears first the description of the category and then the links of the post in that category. However, I want the description to appear below the post links. Could you help me with this, please?

Hi there,

As of right now, the description is hard-coded into the same function that displays the title. This means we can only move it if we move the title as well.

In GP 2.3, we'll be hooking the description into the title function, which means we'll be able to move the description elsewhere easily.

I suppose we could completely remove the element added by GP and add our own custom title and description? Would that work for you?

Let me know :)

I see. As there are tens of categories, it will be lots of work to remove and add custom titles and descriptions. So I would like to wait for GP 2.3 release.

You wouldn't need to manually do anything to your categories.

You could just do this:

add_action( 'wp', function() {
    if ( is_category() ) {
        remove_action( 'generate_archive_title', 'generate_archive_title' );
        add_action( 'generate_archive_title', 'tu_custom_archive_title' );
        add_action( 'generate_after_main_content', 'tu_custom_archive_description' );
    }
} );

function tu_custom_archive_title() {
    ?>
        <div class="page-header">
            <h1 class="page-title">
                <?php the_archive_title(); ?>
            </h1>
        </div>
    <?php
}

function tu_custom_archive_description() {
    $term_description = term_description();

    if ( ! empty( $term_description ) ) {
        printf( '<div class="taxonomy-description">%s</div>', $term_description ); // WPCS: XSS ok, sanitization ok.
    }
}

Thanks. But when I use the code above the code here does not work.

I'm not sure I understand. How are you implementing that code?

This archived topic is closed to new replies.