Skip to content
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

Exclude Optimole URLs from Schema Images #854

Open
KingGrizzly opened this issue Nov 11, 2024 · 2 comments
Open

Exclude Optimole URLs from Schema Images #854

KingGrizzly opened this issue Nov 11, 2024 · 2 comments
Labels
new feature Request for a new feature or functionality to be added to the project.
Milestone

Comments

@KingGrizzly
Copy link

What problem does this address?

Images referenced inside of schema markup (for example, rich product snippets) typically send the Optimole image URL to the search engines, not the clean, local URL.

For example:
https://mlyqxds8ijge.i.optimole.com/w:2048/h:1152/q:80/f:best/https://some-site.com/wp-content/uploads/image.jpg

Instead of:
https://some-site.com/wp-content/uploads/image.jpg

What is your proposed solution?

It would be ideal if Optimole could optionally exclude the images referenced inside of the schema markup so they get a normal URL and not the Optimole URL. Basically, I think we want the option to excluded images inside of script tags, or script tags with an ID or class:

<script id="website-schema" type="application/ld+json">...schema content...</script>

Will this feature require documentation? (Optional)

None

@KingGrizzly KingGrizzly added the new feature Request for a new feature or functionality to be added to the project. label Nov 11, 2024
@vytisbulkevicius vytisbulkevicius added this to the 4.0 milestone Mar 3, 2025
@ineagu
Copy link
Contributor

ineagu commented Mar 7, 2025

Something we might need to keep in mind here if we want to do this is to make sure we use the original thumbnail size.

@KingGrizzly
Copy link
Author

KingGrizzly commented Mar 7, 2025

@ineagu Something to watch out for: some users deregister all Wordpress image sizes because Optimole does the image sizing work. This is so Wordpress won't generate a bloated uploads folder, but then there won't be a thumbnail size.

A combination of something like the following:

Image
// Remove default WordPress image sizes
function remove_default_image_sizes( $sizes ) {
    unset( $sizes['thumbnail'] );
    unset( $sizes['medium'] );
    unset( $sizes['medium_large'] );
    unset( $sizes['large'] );
    unset( $sizes['1536x1536'] );
    unset( $sizes['2048x2048'] );

    return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'remove_default_image_sizes' );

// Disable srcset and sizes attributes on images
add_filter( 'wp_calculate_image_srcset', '__return_false' );
add_filter( 'wp_calculate_image_sizes', '__return_false' );
add_filter( 'wp_image_srcset_generation_enabled', '__return_false' );

// Set big image size threshold
add_filter( 'big_image_size_threshold', function() { return 3000; } );

// Optionally remove original large images after resizing
add_filter( 'wp_generate_attachment_metadata', function( $metadata ) {
    if ( isset( $metadata['file'] ) && isset( $metadata['original_image'] ) ) {
        $uploads_dir = wp_upload_dir();
        $original_image = path_join( $uploads_dir['basedir'], $metadata['original_image'] );
        if ( file_exists( $original_image ) ) {
            unlink( $original_image );
        }
    }
    return $metadata;
} );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Request for a new feature or functionality to be added to the project.
Projects
None yet
Development

No branches or pull requests

3 participants