I’m pretty sure this is intended behaviour rather than a bug but I thought I’d raise it in case anyone else comes across it or in case it is worth having some way of preventing it from happening in certain scenarios.
I created a widget which, as part its ‘widget’ function, adds JavaScript to the footer. I then created a page and added the widget to the page builder. When viewing the page I noticed that the script in the footer was being rendered three times instead of one.
It took me a while to realise that the WordPress SEO plugin was attempting to process the content of the widget for use in the og:description and twitter:description meta tags (adding any text content from my widget to these tags’ values). As a side-effect new scripts were being rendered in the footer, once for each tag.
The fix is simply to update WordPress SEO’s meta description field on the page in question so that it doesn’t try to automatically pull the content from the page builder. As an alternative I wondered if a provision could be made for widget authors to prevent certain widgets from being considered as page content by the Yoast SEO plugin.
Hi C,
This is intentional.
I would recommend running a in_the_loop() (sidebar widgets areen’t in the loop) and is_main_query() (if it’s the main loop) check to avoid this.