Open graph tag “og:type”

#559451
  • Resolved Anonymous
    Rank Math free

    Hello, RankMath

    I would like to change the og:type tag for a few pages. I have read your artice:

    https://rankmath.com/kb/open-graph-meta-tags/

    It says I can do it with specifying the “type” parameter in the filter, but I do not where to put it.

    Do I need a child theme? Can I get more instructions?

    Kind regards.

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

    Thank you for contacting us and bringing your concern to our attention.

    In order to change the og:type for some specific pages, you can try to use the following filter on your website:

    add_filter( 'rank_math/opengraph/type', function( $type ) {
        global $post;
        $post_ids = array(1,2,3); // Replace 1,2,3 with your post/page ID(s)
    
        if(!empty($post->ID) && is_numeric($post->ID) && in_array((int)$post->ID, $post_ids)){
            $type = "article"; // Change the type here
        }
    	
        return $type;
    });
    

    Here’s how you can add filter/hook to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how it goes. Looking forward to helping you.

    Thank you.

    Anonymous
    Rank Math free

    Yeah, it helped. I used ChatGPT to modify it, and it gave me this solution:

    <?php

    add_filter( ‘rank_math/opengraph/type’, function( $type ) {
    global $post;
    $product_post_ids = array(147,198,179,196,193,139,162,6);
    $website_post_ids = array(184,157,225,709,12,247,3);

    if(!empty($post->ID) && is_numeric($post->ID)) {
    if (in_array((int)$post->ID, $product_post_ids)) {
    $type = “product”;
    } else if (in_array((int)$post->ID, $website_post_ids)) {
    $type = “website”;
    }
    }

    return $type;
    });

    It works!

    Hello,

    We are glad that you are able to resolve it.

    If you 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.

    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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Open graph tag “og:type”’ is closed to new replies.