Filter to change Facebook/Twitter Titles

#787652
  • Resolved Anonymous
    Rank Math free

    Hi, I have this php snippet to modify SEO title for certain posts. Is there a way to modify only Facebook/Twitter titles the same way, not SEO titles?

    add_filter('rank_math/frontend/title', function ($title) {
        global $post;
    
        // Check if $post is not null and is a valid WP_Post object
        if (!is_a($post, 'WP_Post')) {
            return $title; // Return original title if $post is not valid
        }
    
        // Check if the current page is a single post and belongs to a specific category
        if (is_single() && has_category('videos', $post)) {
            // Modify the title to prepend "VIDEO: "
            $title = $title . "  [Video]";
        }
    
        return $title;
    });
Viewing 1 replies (of 1 total)
  • Hello,

    To modify only the Facebook or Twitter titles in Rank Math, you can use specific filters provided by Rank Math for Open Graph tags. Here is an example of how you can modify the Facebook Open Graph title:

    add_filter('rank_math/opengraph/facebook/og_title', function ($content) {
        // Your custom logic to modify the Facebook Open Graph title
        return $content;
    });

    And here is an example of how you can modify the Twitter Open Graph title:

    add_filter('rank_math/opengraph/twitter_title', function ($content) {
        // Your custom logic to modify the Twitter Open Graph title
        return $content;
    });

    You can place these filter functions in your theme’s functions.php file or a custom plugin. Make sure to adjust the logic inside the functions to suit your specific requirements for modifying the Facebook or Twitter titles.

    If you have any more questions or need further assistance, feel free to ask!

    Sources:
    How to Make Your Theme Rank Math Compatible » Rank Math
    Rank Math SEO Filters and Hooks for Developers – Rank Math
    Bulk Editing Options in the Rank Math SEO Plugin
    How to Fix “Either ‘name’ or ‘item.name’ should be specified” Error » Rank Math

    This is an automated reply from Rank Math Support Bot. If you need further assistance, please reply to this topic and a human support agent will reply to you shortly.

    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 ‘Filter to change Facebook/Twitter Titles’ is closed to new replies.