1

I have my website www.diabeticme.org using a CDN. The CDN creates an og:image URL that is not readable by Twitter card validator. Can I overwrite the CDN URL for og:image only?

Example:

<meta property="og:image" content="//293985-1025743-raikfcquaxqncofqfm.stackpathdns.com/wp-content/uploads/2020/05/jennifer-sepulveda-2-a-compressor.jpg" />

What is should be:

<meta property="og:image" content="https://www.diabeticme.org/wp-content/uploads/2020/05/jennifer-sepulveda-2-a-compressor.jpg" />

I am using Wordpress and Yoast Premium Plugin.

I tried adding the following code to my functions.php but without any succes:

add_filter( 'wpseo_opengraph_image', 'change_opengraph_image_url' );

    function change_opengraph_image_url( $url ) {
        return str_replace('//293985-1025743-raikfcquaxqncofqfm.stackpathdns.com', 'https://diabeticme.org', $url);
    }

Thank you for any input.

Kind regards Ely

1 Answers1

1

The wpseo_opengraph_image filter can only be used to modify the existing og:image. If you wish to change the URL, you will need to hook into the wpseo_opengraph action to add a different image URL.

  • I see indeed I was using the wrong one. I tried multiple tries with the following but also no luck. function my_opengraph_url( $url ) { return str_replace( 'https://293985-1025743-raikfcquaxqncofqfm.stackpathdns.com', 'https://diabeticme.org', $url ); } add_filter( 'wpseo_opengraph_url', 'my_opengraph_url' ); – Ely Fornoville Jun 02 '20 at 07:17