Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello @readysite

    I’m sorry, but I do not know what you’re referring to here. Where are you trying to add these numbers, specifically?

    Can you please provide a detailed description of what you’re trying to do? I may be able to point you in the right direction. ??

    Thanks.

    Thread Starter readysite

    (@readysite)

    in the category name h1 at the end, and in the page title

    I want to display the number of posts in a category

    I found this code on the forum and I can’t adjust it to the theme:

    function custom_add_count_on_archive_title( $title ) { $term = get_queried_object(); if( $term instanceof WP_Term && ‘category’ === $term->taxonomy ) { $title .= ‘ (‘.$term->count.’)’; } return $title; } add_filter( ‘get_the_archive_title’, ‘custom_add_count_on_archive_title’, 10, 1 );

    Hello @readysite

    From what we can see, you have added the wrong priority to that snippet of code. It should be 20 instead of 10, something like this –

    function custom_add_count_on_archive_title( $title ) {
    $term = get_queried_object();

    if( $term instanceof WP_Term && 'category' === $term->taxonomy ) {
    $title .= ' ('.$term->count. ') ';
    }

    return $title;
    }

    add_filter( 'get_the_archive_title', 'custom_add_count_on_archive_title', 20, 1 );

    One important thing to note here is that in the future, we will not be able to provide support for custom code as this is something that’s not directly related to the theme. If you require such assistance, we recommend contacting a knowledgeable developer. ??

    Hope this helps!

    Thanks.

    Thread Starter readysite

    (@readysite)

    it worked! thanks, you are the best

    You are welcome, @readysite ?? ???♂?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding category count’ is closed to new replies.