Site logo

Archived topic

Category Descriptions Not Displaying

15 replies · Started by Andy on June 30, 2018

Viewing posts 1–15 of 16

Hi,

I'm using WP Show Posts to display my posts but the Category Descriptions are'nt displaying.

Any ideas?

No, I want to show them between the page header and the start of the first post. I understand GP shows them by default so wondering why they aren't for me.

That's because you are using page header which is replacing the normal header with the description.

If you want to show them between the page header and first post, then you will need to build the shortcode using Tom's method, then insert them with the generate_before_main_content hook.

Ok I tried the following in the 'Before Content' field using the GP Hooks Add-on but nothing displayed including my posts.

<?php if (is_category( '' )) 

add_shortcode( 'term_description', 'tu_term_description' );
function tu_term_description() {
    ob_start();
    echo term_description( get_queried_object()->term_id', 'category' );
    return ob_get_clean();
}

<?php endif; ?>

Any further help appreciated.

Add this code:

add_shortcode( 'term_description', 'tu_term_description' );
function tu_term_description() {
    ob_start();
    echo term_description( get_queried_object()->term_id, 'category' );
    return ob_get_clean();
}

Using one of these methods: https://docs.generatepress.com/article/adding-php/

Then you can just add this in hooks:

<?php if ( is_category() ) : ?>
    [term_description]
<?php endif; ?>

Thanks I must have had a brain fart trying to insert the shortcode like I was. When trying to add the shortcode code using the Snippets plugin it's giving me this error:

Don't Panic
The code snippet you are trying to save produced a fatal error on line 4:

syntax error, unexpected '', '' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ')'
The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.

Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.

Any ideas?

Edited the code above.

Thanks Leo it's working now. Unfortunately it was adding the description before EVERY posted listed in the archive, so I moved the shortcode code to the 'Inside Content Container' and it now displays just once before the posts are listed. The only small issue with this is at 768px or below, because it's not inside an article wrapper it has no left or right padding, so the text runs right to the edge of the pages. I can't add any CSS and padding to it without it affecting the posts listed below it.

If you check the URL I provided when I started this thread you will be able see what I mean.

Try this instead:

<?php if ( is_category() ) : ?>
    <div class="cat-description">[term_description]</div>
<?php endif; ?>

Then this CSS:

@media (max-width: 768px) {
    .cat-description {
        margin-left: 20px;
    }
}

Thanks Leo I had already tried something similar but it was adding the margin/padding to the whole page container, however it's working with your code so not sure what I had done differently.

Thank you.

No problem :)

Hello there.I had same issue and came across this forum topic.My description in category page was also not showing.After trying many codes etc i found out that if we don't have any blogs related to that category it wont show up the description.As soon as i added one blog under that category,description of my category pages started showing.Hope this helps.

Thanks for sharing the solution :)

Hi Leo,

I'm really trying for find the hooks but I can't find it.

I have Generate Pro, dispatch skin (created a child theme) and I watched the video, but I simply don't know where to add the hooks. 🤷🏼‍♀️

Can you please help.

I'm trying to have the category descriptions show.

Thank you,
Maike

This archived topic is closed to new replies.