Skip to content

Allow Embed Optimizer to work in Classic block and with Classic Editor #2226

@westonruter

Description

@westonruter

Embed Optimizer includes this line in the description:

Please note that the optimizations are intended to apply to Embed blocks. So if you do not see optimizations applied, make sure that your embeds are not inside a Classic Block.

I recall this was done because only Embed blocks have a FIGURE wrapper which we can use to consistently use with the intersection observer. And it's for the sake of being able to use the plugin with Optimization Detective, so the tag visitor can locate embeds via the FIGURE and child DIV with the expected classes:

/**
* Determines whether the processor is currently at a figure.wp-block-embed tag.
*
* @since 0.3.0
*
* @param OD_HTML_Tag_Processor $processor Processor.
* @return bool Whether at the tag.
*/
private function is_embed_figure( OD_HTML_Tag_Processor $processor ): bool {
return (
'FIGURE' === $processor->get_tag()
&&
true === $processor->has_class( 'wp-block-embed' )
);
}
/**
* Determines whether the processor is currently at a div.wp-block-embed__wrapper tag (which is a child of figure.wp-block-embed).
*
* @since 0.3.0
*
* @param OD_HTML_Tag_Processor $processor Processor.
* @return bool Whether the tag should be measured and stored in URL Metrics.
*/
private function is_embed_wrapper( OD_HTML_Tag_Processor $processor ): bool {
return (
'DIV' === $processor->get_tag()
&&
true === $processor->has_class( 'wp-block-embed__wrapper' )
);
}

For sites using embeds in Classic blocks with or without Optimization Detective, I think we could possibly support them by explicitly filtering the embeds to inject the FIGURE > DIV wrappers.

See also: support forum topic

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Plugin] Embed OptimizerIssues for the Embed Optimizer plugin (formerly Auto Sizes)[Type] EnhancementA suggestion for improvement of an existing feature

    Projects

    Status

    Not Started/Backlog 📆

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions