%% Code for Categories

#13917
  • Resolved Project Studios
    Rank Math free

    Is there any option to make a “post counter” in Category titles? For example: 21 Egg Recipes, and when you publish a new post, it changes to 22.

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

    Thank you for contacting Rank Math today.

    Yes this is possible, you can use the replacement varible %count(varname)% and define a custom variable name that will be used to save the current category value. This will then increment the value by one.

    Looking forward to helping you. Thank you.

    ​​​​​​

    How can I define that variable?

    Hello,

    Apologies for the delay.

    This variable may not be suitable for this use case, the %count(varname)% is designed for use when the posts appear on the same page and varname can be any name identifier such as “my_counter”.
    For your requirement, I can suggest that you create a unique title by registering some custom PHP code to register a custom category title on your theme’s functions.php file.

    Here is an example to get the total count of the current posts on the site and return the value on the category title:

    /**
     * Filter to change the Rank Math category page title.
     * 
     * @param string $title
     */
    add_filter( 'rank_math/frontend/title', function( $title ) {
    	if(is_category()){
    			$categories = get_the_category();
    			$cat = $categories[0];
    			$count = $cat->count;
    			return $count." "."Egg Recipes";
    	}
    	return $title;
    });

    I hope this info helps. Thank you.

    Thank you very much!

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/?rate=5#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘%% Code for Categories’ is closed to new replies.