Closed Pcosta88 closed 1 year ago
Related to sitemaps, it's more general issue. Example of the content:
[et_pb_row]
[et_pb_column]
[et_pb_text]
<p>[gallery link="file" size="full" ids="4392,4393" orderby="rand"]</p>
[/et_pb_text]
[/et_pb_column]
[/et_pb_row]
[/et_pb_section]
It's fixed in #13797, but because Divi builder runs all shortocodes in the content, their developers should exclude gallery from the filter _wpseo_sitemap_content_before_parsehtml. It's better for performance, because _WPSEO_Sitemap_ImageParser will use faster way to extract image IDs and 3rd plugins will not make mess in the code (lazy loading,...) which could block parsing.
Example of optimized code includes/builder/plugin-compat/wordpress-seo.php:
/**
* Hook methods to WordPress
* Latest plugin version: 3.1.1
* @return void
*/
public function init_hooks() {
// Bail if there's no version found
if ( ! $this->get_plugin_version() ) {
return;
}
// Enable Sitemap Cache
add_filter( 'wpseo_enable_xml_sitemap_transient_caching', '__return_true' );
add_filter( 'wpseo_build_sitemap_post_type', array( $this, 'load_builder_modules_early' ) );
}
/**
* Loads the builder's modules so that they are loaded before Yoast generates the sitemap.
*
* @param string $type
*/
public function load_builder_modules_early( $type ) {
// Removes filters for "responsive images". It isn't needed for sitemaps.
remove_filter( 'wp_calculate_image_srcset', 'et_filter_wp_calculate_image_srcset', 10, 4 );
remove_filter( 'wp_calculate_image_sizes', 'et_filter_wp_calculate_image_sizes', 10, 4 );
remove_action( 'wp', 'et_builder_init_global_settings', 9 );
remove_action( 'wp', 'et_builder_add_main_elements' );
et_builder_init_global_settings();
et_builder_add_main_elements();
add_filter( 'pre_do_shortcode_tag', array( $this, 'exclude_gallery_shortcode' ), 10, 4 );
add_filter( 'wpseo_sitemap_content_before_parse_html_images', array( $this, 'do_shortcode' ) );
return $type;
}
public function exclude_gallery_shortcode( $content, $tag, $attr, $m ) {
if ( $tag === 'gallery' && $this->preserve_gallery_shortcode ) {
$content = $m[0];
}
return $content;
}
public function do_shortcode( $content ) {
// Check if content includes ET shortcode.
if ( false === strpos( $content, '[et_pb_section' ) ) {
// None found, bye.
return $content;
}
// Render the shortcode.
$this->preserve_gallery_shortcode = true;
$content = apply_filters( 'the_content', $content );
$this->preserve_gallery_shortcode = false;
return $content;
}
Removing filters related to processing srcset and sizes could reduce number of SQL queries. From other side, the sitemap's code uses only src attribute. It could be little optimization related to Divi builder. @lots0logs Could you look it?
We're tracking this on https://github.com/elegantthemes/Divi/issues/17659 I'll keep you posted on the status.
@lots0logs I'm updating Divi's team with my thoughts about this issue.
Related to class _ET_Builder_Plugin_Compat_WordPressSEO, I think that's more efficient to use filter _wpseo_build_sitemap_posttype (WPML uses this way and I didn't notice any issue) to add/remove filters for sitemap requests (instead of action _pre_getposts). For example, query variable xsl is deprecated and it's replaced with yoast-sitemap-xsl (anyway, it doesn't affect current code in this class).
It seems that option "Enable Divi gallery" can transform "HTML code" in something like this:
<div class="et_pb_slide" style="background:url(.../Weddings/PLL_9852.jpg);"></div>
<div class="et_pb_slide" style="background:url(.../Weddings/PLP_3105.jpg);"></div>
So, It can't be parsed in method _parse_htmlimages and I've added following code into method _load_builder_modulesearly:
add_filter( 'et_gallery_layout_enable', '__return_false', 20 );
Other possible issues are related to "lazy load" or other plugins which "filters _thecontent". Jetpack will "photonoize" URLs even it isn't needed. Yoast SEO will ignore them because these URLs contain query strings (or they are external URLs).
I think that's the most efficient solution to Divi "doesn't run" gallery shortcode (as in my code) which will save resources too (Yoast SEO will faster extract all images from the gallery shortcodes).
Also, replacing $post->post_content
with $content
in PR #13797 will reduce 3 parsing ( _apply_filter( 'thecontent', ... ) - Divi, _hasshorcode( 'gallery' ) and _preg_matchall ) for all shortcodes to single parsing and it's possible that themes/plugins transform somehow gallery shortcodes by filter _wpseo_sitemap_content_before_parse_htmlimages.
I think that these changes and PR #13797 could fix/optimize current code in both plugins.
I'm testing these changes on few websites and it seems that works as should. Also, I see performance improvements.
This issue is partially fixed by #13797. I'm reopening it to we track changes related to Divi updates.
PR #13797 is merged and it's part of next release (12.7) and there is pre-release version 12.7RC1 (and 12.7RC2).
I'm updating my code based on the latest testing:
/**
* Hook methods to WordPress
* Latest plugin version: 3.1.1
*
* @return void
*/
public function init_hooks() {
// Bail if there's no version found.
if ( ! $this->get_plugin_version() ) {
return;
}
// Enable Sitemap Cache.
add_filter( 'wpseo_enable_xml_sitemap_transient_caching', '__return_true' );
add_filter( 'wpseo_build_sitemap_post_type', array( $this, 'load_builder_modules_early' ) );
}
/**
* Loads the builder's modules so that they are loaded before Yoast generates the sitemap.
*
* @param string $type
*/
public function load_builder_modules_early( $type ) {
// Removes filters for "responsive images". It isn't needed for sitemaps.
remove_filter( 'wp_calculate_image_srcset', 'et_filter_wp_calculate_image_srcset', 10, 4 );
remove_filter( 'wp_calculate_image_sizes', 'et_filter_wp_calculate_image_sizes', 10, 4 );
add_filter( 'et_gallery_layout_enable', '__return_false', 20 );
remove_action( 'wp', 'et_builder_init_global_settings', 9 );
remove_action( 'wp', 'et_builder_add_main_elements' );
// Load modules.
et_builder_init_global_settings();
et_builder_add_main_elements();
add_filter( 'pre_do_shortcode_tag', array( $this, 'exclude_gallery_shortcode' ), 10, 4 );
add_filter( 'wpseo_sitemap_content_before_parse_html_images', array( $this, 'do_shortcode' ) );
return $type;
}
/**
* Preserve gallery shortcode in "the_content".
*/
public function exclude_gallery_shortcode( $content, $tag, $attr, $m ) {
if ( 'gallery' === $tag && $this->preserve_gallery_shortcode ) {
$content = $m[0];
}
return $content;
}
public function do_shortcode( $content ) {
// Check if content includes ET shortcode.
if ( false === strpos( $content, '[et_pb_section' ) ) {
// None found, bye.
return $content;
}
// If the shortcode outputs something then catch it and clean output buffer.
ob_start();
// Render the shortcode.
$this->preserve_gallery_shortcode = true;
$content = apply_filters( 'the_content', $content );
$this->preserve_gallery_shortcode = false;
ob_end_clean();
return $content;
}
I've added output buffers because it could fix #12302 and prevent sitemap breaking.
Backward compatibility is fine because it improves performance if there is the latest Yoast SEO. If someone uses older versions (Yoast SEO) then galleries will be parsed from $post->post_content
and maybe there will be duplicated images (if there are images detected by HTML parser and additionally images detected by gallery parser) - similar issue #12110.
Please inform the customer of conversation # 588679 when this conversation has been closed.
Please inform the customer of conversation # 591081 when this conversation has been closed.
Still relevant in Yoast SEO v13.2 and Divi v4.4.0.
Please inform the customer of conversation # 592146 when this conversation has been closed.
Please inform the customer of conversation # 597252 when this conversation has been closed.
User also say to
...consider that the image module can have an image as a background not specifically in the image attribute in the module. This can also happen in other modules and even in the sections. On my homepage I have this particular set up on some modules
.
Please inform the customer of conversation # 598192 when this conversation has been closed.
Please inform the customer of conversation # 612800 when this conversation has been closed.
Please inform the customer of conversation # 613554 when this conversation has been closed.
Please inform the customer of conversation # 615312 when this conversation has been closed.
Please inform the customer of conversation # 629022 when this conversation has been closed.
Still happens with Yoast SEO v14.5 and Divi v4.5.1.
Please inform the customer of conversation # 632671 when this conversation has been closed.
Please inform the customer of conversation # 633203 when this conversation has been closed.
Please inform the customer of conversation # 645027 when this conversation has been closed.
Please inform the customer of conversation # 656830 when this conversation has been closed.
Please inform the customer of conversation # 661286 when this conversation has been closed.
Please inform the customer of conversation # 671215 when this conversation has been closed.
Edit: According to changelog: https://www.elegantthemes.com/api/changelog/divi.txt Divi v3.0.77 (which was on 29th of September, 2017) added a fix for the images in the Image Module to count them in the sitemap.
Please inform the customer of conversation # 692223 when this conversation has been closed.
Please inform the customer of conversation # 729243 when this conversation has been closed.
Please inform the customer of conversation # 732864 when this conversation has been closed.
I tested this with the latest versions: Yoast SEO 20.3 and Divi 4.20.2 and I can no longer reproduce the issue. Both the image module and gallery module are seen in our SEO analysis and they are added to our sitemap. Closing.
Please give us a description of what happened.
Images added by Divi Image or Gallery Module fail to be picked-up scanned parsed by Yoast and do not show on sitemap
Please describe what you expected to happen and why.
As per this issue report https://github.com/Yoast/wordpress-seo/issues/4808 they would (or at least the image module should)
How can we reproduce this behavior?
1. Add an image using Divi Gallery Module or Image
Gallery
Image
2. Run webworker tool on it and see it only picks up the text
3. Check sitemap and see that it fails to appear
Technical info
Used versions