Open bobbingwide opened 7 years ago
I don’t think I changed anything but I can’t reproduce the problem using my iPad on cwiccer.com with the Google Maps block in a post. There is a simple explanation. Within the logic to get_the_excerpt()
, called by WordPress SEO to determine the Opengraph description, is a call to excerpt_remove_blocks()
. This allows core/paragraph
block and other blocks, but not the oik-block/googlemap
block. WordPress SEO therefore doesn't cause the [bw_show_googlemap] shortcode to be expanded as it's been stripped from the content.
When the shortcode is added directly, in a paragraph block, then it'll get expanded. Another workaround would be to include the shortcode in a shortcode block.
So that's two more workarounds.
Maybe I should just write a FAQ about this. Concentrate on the other challenges when content is expanded during REST API processing.
Sometimes when viewing content which contains the [bw_show_googlemap] shortcode the Google map is not displayed. The problem occurs when Yoast SEO is activated.
Expected output
Actual output
Explanation
During display of the content Yoast SEO attempts to determine the content to use in meta property tags. Some of this content is determined from the value for the Meta description ( meta_key=_yoast_wpseo_metadesc ). If this post meta data is not set Yoast SEO attempts to determine it using
get_the_excerpt()
.get_the_excerpt()
can cause thethe_content
filter to be executed[bw_show_googlemap]
being expanded.bw_googlemap_v3()
generates JavaScript which it assumes will be output to the browser.the_content
filters.the_content
is performed for the actual display, the first lump of JavaScript is missing.Workaround
Admin only notice: this page doesn't show a meta description because it doesn't have one, either write it for this page specifically or go into the SEO -> Titles menu and set up a template.
Setting up the template for each post type is the easiest workaround to implement as it will apply for every affected post.
Proposed solution
Yoast SEO tries to get a value for
_yoast_wpseo_metadesc
for every page being displayed. It's more efficient for the_yoast_wpseo_metadesc
field to be populated when the post is saved; save once - display many.This is true for every page, regardless of the shortcodes that may or may not be used in the content / generated content. So our solution should automatically set
_yoast_wpseo_metadesc
if it's not already set.I don't think we need to test whether or not Yoast SEO is activated.
Alternative solution
Change the shortcode to enqueue the JavaScript so that the workaround is not required.