Image from Jet Custom Field for Facebook and Twitter cards

#393457
  • Resolved Victor Koumantakis
    Rank Math free

    Hello!

    I am using these snippets in order to use a custom image field (agg-img) from a custom post type (Events) from JetEngine to Facebook and Twitter cards. They don’t work… Could you please help me? Thank you!

    add_filter( 'rank_math/opengraph/facebook/image', function( $horizontal_img_path ) {
    $post_meta = get_post_meta( get_the_id(), 'agg-img', true );
    if ( $post_meta ) {
    return $post_meta;
    }

    return $img_path;
    });

    add_filter( 'rank_math/opengraph/twitter/image', function( $horizontal_img_path ) {
    $post_meta = get_post_meta( get_the_id(), 'agg-img', true );
    if ( $post_meta ) {
    return $post_meta;
    }

    return $img_path;
    });

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

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

    It seems that you are also returning an undefined variable for your filters. Kindly try this code instead:

    add_filter( 'rank_math/opengraph/facebook/image', function( $horizontal_img_path ) {
        $post_meta = get_post_meta( get_the_id(), 'agg-img', true );
    
        if ( $post_meta ) {
            $horizontal_img_path = $post_meta;
        }
    
        return $horizontal_img_path;
    });
        
    add_filter( 'rank_math/opengraph/twitter/image', function( $horizontal_img_path ) {
        $post_meta = get_post_meta( get_the_id(), 'agg-img', true );
    
        if ( $post_meta ) {
            $horizontal_img_path = $post_meta;
        }
            
        return $horizontal_img_path;
    });

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

    Unfortunately, it doesn’t work. Into the Facebook debugger it is showing me the logo image instead of the custom image. I cleared the cache also.

    Hello,

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    I just did send you the data. Thank you!

    Hello,

    The field aggeltirio-img in the database has an integer value for most of the posts as you can see from this screenshot:
    Postmeta value

    In order for the image to be fetched from a custom field the value in the custom field needs to be an image and not an integer as it is currently.

    Also, this filter is used to change the current og:image and since on those pages no value is added to this meta tag you need to add a featured image to the pages and then proceed to replace it with the values you wish via a custom field.

    Don’t hesitate to get in touch if you have any other questions.

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

The ticket ‘Image from Jet Custom Field for Facebook and Twitter cards’ is closed to new replies.