Home › Forums › Support › AMP and WP Show Posts: can jquery scripts in GP themes (WPSP) be ‘AMP-ized’?
- This topic has 3 replies, 2 voices, and was last updated 3 years, 3 months ago by
Tom.
-
AuthorPosts
-
August 20, 2020 at 6:25 am #1410952
Nicolaas
Hello,
I have added AMP plugin to my new site. Overall works fine with GP AMP add-on installed. Only one issue with Home Page which seems to be triggered by WPSP jquery script (matchHeight). Is there any work-around to ÁMP-ize’ this script into AMP-script? I know how to do some coding but fro this specific case I need help.
Thanks,
Nicolaas
This is the message I am getting:
Invalid script: jquery.js
Details
JSwp-includes
Markup Status
Removed
Information
Arbitrary JavaScript is not allowed in AMP. You cannot use JS <script> tags unless they are for loading AMP components (which the AMP plugin will add for you automatically). In order for a page to be served as AMP, the invalid JS code must be removed from the page. Learn more about how AMP works. As an alternative to using custom JS, please consider using a pre-built AMP functionality, including actions and events (as opposed to JS event handler attributes like onclick) and the amp-bind component; you may also add custom JS if encapsulated in the amp-script.If you remove the invalid markup then it will not block this page from being served as AMP. Note that you need to check what impact the removal of the invalid markup has on the page to see if the result is acceptable. If you keep the invalid markup, then the page will not be served as AMP.
Error code
DISALLOWED_TAG
Invalid markup
<script … >
Element attributes
type text/javascript
src https://XXX.com/wp-includes/js/jquery/jquery.js
id jquery-js
Element name
script
Parent element
body
Sources
#1 Type: Core
Name: wp-includes
Function: do_shortcode()
Action: the_content (priority 11)
Enqueued Script: wpsp-matchHeight
Dependent Script: jquery
Location: shortcodes.php:196
#2 Type: Core
Name: wp-includes
Function: wp_default_scripts()
Action: wp_default_scripts (priority 10)
Enqueued Script: jquery
Location: script-loader.php:584
#4 Type: Core
Name: wp-includes
Function: WP_Widget_Factory::_register_widgets()
Action: widgets_init (priority 100)
Enqueued Script: jquery
Location: class-wp-widget-factory.php:89
#6 Type: Core
Name: wp-includes
Function: wp_widgets_init()
Action: init (priority 1)
Enqueued Script: jquery
Location: widgets.php:1725
#8 Type: Core
Name: wp-includes
Function: wp_print_footer_scripts()
Action: wp_footer (priority 20)
Location: script-loader.php:1976
#9 Type: Core
Name: wp-includes
Function: _wp_footer_scripts()
Action: wp_print_footer_scripts (priority 10)
Location: script-loader.php:1966
Select bed2d5b10c89c46a8516e4e400b2ed95 Invalid script: jquery.matchHeight.js
Detailswp-includes
Markup Status
Removed
Information
Arbitrary JavaScript is not allowed in AMP. EtcError code
DISALLOWED_TAG
Invalid markup
<script … >
Element attributes
type text/javascript
src https://XXX.com/wp-content/plugins/wp-show-posts/js/jquery.matchHeight.js
id wpsp-matchHeight-js
Element name
script
Parent element
body
Sources
#1 Type: Core
Name: wp-includes
Function: do_shortcode()
Action: the_content (priority 11)
Enqueued Script: wpsp-matchHeight
Location: shortcodes.php:196
#2 Type: Core
Name: wp-includes
Function: wp_print_footer_scripts()
Action: wp_footer (priority 20)
Location: script-loader.php:1976
#3 Type: Core
Name: wp-includes
Function: _wp_footer_scripts()
Action: wp_print_footer_scripts (priority 10)
Location: script-loader.php:1966August 20, 2020 at 2:35 pm #1411812Tom
Lead DeveloperLead DeveloperHi there,
That script will be removed in the next WPSP version.
For now, try this:
add_action( 'wp_print_scripts', function() { wp_dequeue_script( 'wpsp-matchHeight' ); }, 999 );
August 21, 2020 at 2:49 am #1412270Nicolaas
Thanks Tom,
I guess this may solve matchHeight error; not jquery as such? added the code in a snippet (run snippet everywhere) and tried it out. In AMP I still get the error message. So what does matchHeight do? The good news if I remove it via AMP I see no effect on front-end.
Cheers,
Nicolaas
August 21, 2020 at 8:56 am #1412906Tom
Lead DeveloperLead DeveloperIt’s an old compatibility thing for browsers that don’t support flexbox – not needed anymore.
jQuery may still be loading if another script on your site is depending on it.
-
AuthorPosts
- You must be logged in to reply to this topic.