Quantity of posts in archive title

#518695
Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    Rank Math does not have a variable to retrieve the count of posts in a category. In this case, you may need to create a custom variable for that:

    /**
     * Action: 'rank_math/vars/register_extra_replacements' - Allows adding extra variables.
     * Snippet to register variable that will return the number of posts in the current term
     */
    add_action('rank_math/vars/register_extra_replacements', function () {
        rank_math_register_var_replacement(
            'term_count',
            [
                'name'        => esc_html__('Term Count', 'rank-math'),
                'description' => esc_html__('Number of posts in the current term', 'rank-math'),
                'variable'    => 'term_count',
                'example'     => term_count_callback(),
            ],
            'term_count_callback'
        );
    });
    function term_count_callback()
    {
        $term = get_queried_object();
        return isset($term) ? $term->count : null;
    }

    And here’s a guide to adding the code to the website:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Once done, you can use %term_count% in the title.

    Hope that helps.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Quantity of posts in archive title’ is closed to new replies.