bobbingwide / oik

OIK Information Kit
https://www.oik-plugins.com/oik-plugins/oik
GNU General Public License v2.0
2 stars 0 forks source link

[bw_show_googlemap] leads to Uncaught ReferenceError: google is not defined #85

Open bobbingwide opened 7 years ago

bobbingwide commented 7 years ago

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

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.

bobbingwide commented 4 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.

  1. Use the Google Maps block - oik-block/googlemap
  2. Use the Shortcode block. - core/shortcode
bobbingwide commented 4 years ago

Maybe I should just write a FAQ about this. Concentrate on the other challenges when content is expanded during REST API processing.