Set Titel conditionally

#878881
  • Resolved Tom Filbrandt
    Rank Math free

    Dear Team,

    I want to make sure that my titles and descriptions are never longer than a certain number of chars. But I would like to do it conditionally, like if its longer than 160 then use this schema, otherwise use that schema. Is there any way, even programmatically to do it? Any filters?

    Best wishes, Tom

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

    We apologize for the issue you are facing. Currently, Rank Math does not provide a built-in feature to set titles and descriptions conditionally based on character length directly within the plugin settings. However, you can achieve this programmatically by using WordPress filters.

    You can use the rank_math/frontend/title filter to modify the title based on its length. Here’s a basic example of how you might implement this in your theme’s functions.php file:

    add_filter('rank_math/frontend/title', function($title) {
        if (strlen($title) > 160) {
            // Use your alternative schema or title here
            return 'Your alternative title';
        }
        return $title; // Return the original title if it's within the limit
    });

    Similarly, you can use the rank_math/frontend/description filter for descriptions:

    add_filter('rank_math/frontend/description', function($description) {
        if (strlen($description) > 160) {
            // Use your alternative schema or description here
            return 'Your alternative description';
        }
        return $description; // Return the original description if it's within the limit
    });

    This way, you can conditionally set your titles and descriptions based on their length. If you have further questions or need assistance with implementation, please reply to this ticket, and a human agent from the Rank Math Support team will assist you.

    Thank you for raising this concern!

    Sources:
    Rank Math ‘Titles and Meta’ Options and Settings

    Hello,

    It seems like you’ve marked this ticket as resolved.

    Can you please confirm if you still need our assistance with anything else or we can close the ticket?

    Looking forward to hearing back from you.

    Thank you.

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

You must be logged in to reply to this ticket.