0

So I've always used the following code snippet to force the default OG:Image and Twitter:Card image:

add_filter('wpseo_pre_analysis_post_content','mysite_opengraph_content');
function mysite_opengraph_content($val){return '<img src="https://www.rafaeldejongh.com/wp-content/uploads/2017/08/RafaelDeJongh-Web-Developer-3D-Artist.jpg" alt="Rafaël De Jongh - Web Developer | 3D Artist"/>' . $val;}

However this doesn't seem to work anymore, does anyone know a different way to solve this like it did in the past with above mentioned code?

Or in a way to improve upon this code I mocked up:

function default_opengraph(){return 'https://www.tzotkiekske.be/wp-content/uploads/2017/10/tzotkiekske-fb.jpg';}
add_filter('wpseo_opengraph_image','default_opengraph');
add_filter('wpseo_twitter_image','default_opengraph');

But which allows to add this to the OG:Images rather than replace it.

1 Answer 1

1

The action that allows an OG image to be added seemed to be the thing I was looking for, so much for proper documentation on their side. But now the only thing I'm wondering if the following code I made up is the proper way to deal with it:

$default_opengraph = 'https://www.rafaeldejongh.com/wp-content/uploads/2017/08/RafaelDeJongh-Web-Developer-3D-Artist.jpg';
function add_default_opengraph($object){global $default_opengraph; $object->add_image($default_opengraph);}
add_action('wpseo_add_opengraph_images','add_default_opengraph');
function default_opengraph(){global $default_opengraph; return $default_opengraph;}
add_filter('wpseo_twitter_image','default_opengraph');

As well as this one doesn't add additional twitter:images but as far as I know there should also only be one for this.

But at least it's a "solution" to my question rather than down voting this question, I would've loved to hear some feedback on it!

Not the answer you're looking for? Browse other questions tagged or ask your own question.