-
Notifications
You must be signed in to change notification settings - Fork 882
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
Add new filter: wpseo_sitemap_content_before_parse_html
#7251
Add new filter: wpseo_sitemap_content_before_parse_html
#7251
Conversation
…e post content to be filtered before it is parsed for images (for the xml sitemap). This will allow themes and plugins to process their own shortcodes if they wish to have the images properly included in the sitemap. Fixes Yoast#4808 Fixes elegantthemes/Divi#2369 Related Yoast#6040
Yoast SEO already has filter for image parsing ( Thrive Visual Editor already uses this hook. I've seen more examples related to theme/plugins. I've developed similar system for VC (for my websites) - related to #6041. |
Yes I realize that. However, using that hook requires implementing a lot of the logic that is already implemented in the |
Just info from #4500:
Also, I had issues related to PS: It can't help for #6040 because URLS is part of |
It works in Divi 😃 Obviously it won't work in all cases, but that's okay because it's not intended to. Anyone hooking into this new hook would be doing so having made sure it works with their code. |
Also, I don't think the concerns discussed on #4500 are relevant to this PR as the filter only deals with post content (not the post object being used by the parser). |
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.
I have done a review on your pull.
/** | ||
* Filters the post content before it is parsed for images. | ||
* | ||
* @param string $content |
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.
Can you add some docs about the $content`
@param string $content The post content.
It might be better to use this format for documenting the hook:
/**
* Filter: 'wpseo_sitemap_content_before_parse_html' - Filters the post content before it is parsed for images.
*
* @api string $content The post content.
*/
* | ||
* @param string $content | ||
*/ | ||
$content = apply_filters( 'wpseo_sitemap_content_before_parse_html', $post->post_content ); |
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.
I think wpseo_sitemap_content_before_parse_html_images
would be a more descriptive name.
Instead of introducing a new filter we might consider using the WordPress way. I think that way is handling shortcodes as well.
|
I think that would make a lot of sense in this specific case. Honestly, all we would be doing with the new filter in Divi is applying |
@andizer I've incorporated your feedback. |
We are discussing the approach internally to make sure we are going forward with it in the most optimal way. The decision is between introducing a performance heavy filter, with limited context awareness: As this is 'just' an image count for the sitemaps the impact should be a minimal as possible. |
@moorscode can we make a decision on this one? |
Been reading on this, it seems like a good addition but I'd also think that makes it a LOT slower... At the same time, most of this is usually cached, so I'm going to go ahead and approve this. |
@andizer if you don't have further objections, I'd say merge! |
Summary
Add new filter:
wpseo_sitemap_content_before_parse_html
to allow the post content to be filtered before it is parsed for images (for the xml sitemap). This will allow themes and plugins to process their own shortcodes if they wish to have the images properly included in the sitemap.Relevant technical choices:
Test instructions
Fixes #4808
Fixes elegantthemes/Divi#2369
Related #6040