-
Notifications
You must be signed in to change notification settings - Fork 823
Open Graph Meta Tags: add new fallback image #44336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
Fixes CML-608 This leverages the Social Image Generator library to dynamically generate a better social preview image for sites, based off any image we can find from the site (using the same logic as before), but framing that image and display the site title so the whole preview looks better. This is currently not something that can be customized via a UI yet. - It uses the `edge` template from Social Media Generator because it seems to be the template that best fits social previews. - The `jetpack_og_fallback_social_image_template` filter allows one to define their own template instead. - If the Social Image Generator features are not available, we fall back to the previous behavior. - The dynamically generated image src is stored in a transient for a day, to avoid putting too much strain on the service.
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
Full summary · PHP report · JS report Coverage check overridden by
I don't care about code coverage for this PR
|
Give the transient a more specific name so it can get flushed when the source of the image changes.
That should make for easier testing
This will avoid conflicts when a site's representative image is updated
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds dynamic fallback social preview images using the Social Image Generator and integrates this into the existing Open Graph logic.
- Implements
jetpack_og_get_fallback_social_image
,jetpack_og_get_site_image
, and related helpers to build or fall back to blank/site assets. - Introduces caching of generated social image tokens and exposes filters for template selection.
- Adds unit tests for the new Open Graph helper functions and updates the changelog.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
functions.opengraph.php | Refactors site‐image fallbacks, adds dynamic social image generation functions, filters, and token caching |
tests/php/Functions_OpenGraph_Test.php | Adds tests and data providers for new Open Graph helpers |
changelog/add-social-media-fallback-open-graph | Documents the new fallback image enhancement |
Comments suppressed due to low confidence (3)
projects/plugins/jetpack/functions.opengraph.php:536
- Add unit tests for jetpack_og_get_available_templates to verify it returns the expected template list both when the Social Image Generator is available and when it is not.
function jetpack_og_get_available_templates() {
projects/plugins/jetpack/functions.opengraph.php:555
- Add unit tests for jetpack_og_get_social_image_token to cover its caching behavior, the error path when the generator is unavailable, and successful token retrieval via filter or actual fetch.
function jetpack_og_get_social_image_token( $site_title, $image_url, $template ) {
projects/plugins/jetpack/functions.opengraph.php:405
- Add unit tests for jetpack_og_get_fallback_social_image to ensure the fallback sequence (blank, representative image, template choice) behaves as expected.
function jetpack_og_get_fallback_social_image( $width, $height ) {
Follow-up to #44336 When requesting a token directly from a WordPress.com simple site, we should check for the capability first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this Jeremy!
I have some question with the following scenario:
- Created a new JN site with this branch
- Checked the homepage, it had no
og:image
tags - that's expected. - Turned on publicize.
- Checked the homepage, now it has
og:image
, but it's the blank image and does not contain the site name. This is expected as I don't have the paid plan right?

- Added the Jetpack Social paid plan
- OG image is now SIG image with highway template ✅
- Setting an icon uses SIG image with edge ✅
- I turned off the module,
og:image
is now not set on the homepage ✅ - I turned the module back on, and shared a post with SIG
- Now on the homepage the
og:image
is not the site title, but the last post's og image.


Is that expected or should I still see the site title and logo for the site homepage og:image
?
Thanks for taking a look at it!
Correct.
That's a good catch, I hadn't tested that. It appears to be a bug with Social Image Generator. I opened #44377 to get this fixed. |
// Build the image URL and return it. | ||
return array( | ||
'src' => sprintf( | ||
'https://s0.wp.com/_si/?t=%s', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See Automattic/jetpack#44336 (review) Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/16435824701 Upstream-Ref: Automattic/jetpack@48651d2
See Automattic/jetpack#44336 (review) Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/16435824701 Upstream-Ref: Automattic/jetpack@48651d2
See Automattic/jetpack#44336 (review) Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/16435824701 Upstream-Ref: Automattic/jetpack@48651d2
See Automattic/jetpack#44336 (review) Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/16435824701 Upstream-Ref: Automattic/jetpack@48651d2
Fixes CML-608
Note
We'll need to merge #44350 and #44377 before we can merge this.
Proposed changes:
This leverages the Social Image Generator library to dynamically generate a better social preview image for sites, based off any image we can find from the site (using the same logic as before), but framing that image and display the site title so the whole preview looks better.
This is currently not something that can be customized via a UI yet.
jetpack_og_fallback_social_image_template
filter allows one to define their own template instead.Warning
This feature requires a paid plan. It is currently gated with the same gate as the Social Image Generator:
jetpack/projects/plugins/wpcomsh/wpcom-features/class-wpcom-features.php
Lines 1071 to 1078 in 401cc49
Design
I opted to use the
edge
template from Social Media Generator because it seemed to be the template that best fits social previews. However, when there are no images available to use to generate an image, I opted to usehighway
.Here are some screenshots of the different templates currently available:
With a site logo
In my opinion none of the designs work very well when we have no image to work with though. It may be worth creating a new template just for that use-case, but I'm not quite sure how it should look like.
Without any image
Screenshots of the current implementation in this PR
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
CI
On a self-hosted site using Offline mode
=> The behavior should not change.
define( 'JETPACK_DEV_DEBUG', true );
og:image
tagtrunk
.On a paid self-hosted or WoA site
og:image
taghttps://s0.wp.com/_si/
URL.On a WordPress.com Simple site
og:image
taghttps://s0.wp.com/_si/
URL.in Settings > General for example. It should change the generated
image.
og:image
taghttps://s0.wp.com/_si/
URL. => We have a bug here right now. Social Image Generator: restrict direct access to token generation #44350 should fix the problem.