wordpress-seo icon indicating copy to clipboard operation
wordpress-seo copied to clipboard

wpseo_opengraph_image filter is broken

Open shawnlunny opened this issue 11 years ago • 7 comments

I have tried to add the filter to functions.php and in my case I also tried adding it to a MU plugin.

In the filter I got frustrated and so I put nothing but a die('stopped here'); and it is not firing. I saw a closed issue in here from a while back but there was no solution. The author just said they think it could be something else and closed the ticket, but no update was ever published.

I am a developer and can't see why this is not working. Can someone else replicate this?

shawnlunny avatar Feb 28 '15 00:02 shawnlunny

Could you please provide example code snippet verbatim? Also link to the other issue?

Rarst avatar Mar 03 '15 16:03 Rarst

Here is a search of this repository with the different issues historically opened about the same issue.

https://github.com/Yoast/wordpress-seo/search?q=wpseo_opengraph_image&type=Issues&utf8=%E2%9C%93

The posts I had read that seem to relate are the jereckley and palmjack ones in that search. In my case my function is super basic and is not executing. I verified this not only because the php does not execute but also there is no og:image tag in the source. Once again I ran this in the functions.php of the theme AND at the mu-plugin level without success.

function mysite_opengraph_single_image_filter($value){
    var_dump($value); die('stopped');
    return $value;
}
add_filter('wpseo_opengraph_image', 'mysite_opengraph_single_image_filter');

shawnlunny avatar Mar 03 '15 16:03 shawnlunny

Your example code works for me (via mu-plugin) on WP theme test data just fine.

Note that it runs primarily on singular pages that have featured image set or image detected in content. There might be issue with latter step, maybe on specific content.

Rarst avatar Mar 03 '15 17:03 Rarst

If the image is defined in something like metadata for a custom post type, would that be detected or only in something like standard posts? Is there a way to define this?

shawnlunny avatar Mar 03 '15 17:03 shawnlunny

I suppose plugin wouldn't know to look for it in such case.

The small logical issue in the way current code is organized is that filter fires when there is image located. So the filter cannot be used to handle the case where there is no image located and prompted to be displayed.

You could try storing imge URL into plugin's _yoast_wpseo_opengraph-image custom field. In that case plugin should pick up on it.

Rarst avatar Mar 03 '15 17:03 Rarst

Ok is there an action hook or filter to set that custom field?

shawnlunny avatar Mar 03 '15 17:03 shawnlunny

You could use native WordPress hooks. Just whenever you save an image into your own custom field, drop its URL into this one.

Rarst avatar Mar 03 '15 17:03 Rarst