Disable Featured Image on og:image for certain post types

#786816
  • Dan
    Rank Math free

    Hello, our job_listing post type (WP Job Manager) has square logos for the featured images which are unsuitable for og:images. We would like the default og:image to be used. I have tried this snippet to disable it but its having no effect. Thanks in advance!!

    add_filter( ‘rank_math/opengraph/use_post_thumbnail’, function( $use_thumbnail, $post_id ) {
    // Check the post type and conditionally disable setting featured image as og:image
    if ( ‘job_listing’ === get_post_type( $post_id ) ) {
    return false;
    }

    return $use_thumbnail;
    }, 10, 2 );

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

    Thank you for reaching out to us. The code snippet you provided is almost correct, but the filter you are using is not the correct one to disable the featured image as og:image for certain post types.

    To achieve your goal and disable the featured image as og:image for the “job_listing” post type, you should use the following filter instead:

    add_filter( 'rank_math/opengraph/pre_set_content_image', function() {
        return true;
    });

    This filter will override the first image in the post with the default OpenGraph thumbnail, effectively preventing the featured image from being used as og:image for the specified post type.

    Please replace the existing snippet with the one provided above and check if it resolves the issue for you. If you encounter any further difficulties or have additional questions, feel free to let us know. We’re here to help!

    Thank you for your understanding and patience.

    Sources:
    Rank Math SEO Filters and Hooks for Developers – Rank Math
    Open Graph Meta Tags » Rank Math
    How to Make Your Theme Rank Math Compatible » Rank Math

    This is an automated reply from Rank Math Support Bot. Your ticket has been assigned to a human agent and we will get back to you shortly.

    Dan
    Rank Math free

    Please can you provide the full snippet that applies this to the job_listing post type only?

    Hello,

    Thank you for contacting Rank Math support, and we are sorry for any inconvenience that might have been caused due to that.

    To disable the featured image for the job_listing post type and use the default Open Graph image instead, you can add the following code snippet:

    // Disable featured image for job_listing post type
    add_filter( 'rank_math/opengraph/show_image', function( $show_image ) {
        if ( is_singular( 'job_listing' ) ) {
            return false;
        }
        return $show_image;
    });

    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.
    Looking forward to helping you.

    Thank you.

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

You must be logged in to reply to this ticket.