- This topic has 17 replies, 7 voices, and was last updated 5 years, 4 months ago by
David.
-
AuthorPosts
-
October 13, 2020 at 7:58 pm #1487752
Het
So I did a test with no comments Vs having a comment. I use this comment as a SHORTCode via using a child theme. With no comments I don’t get this in google page insights:
Does not use passive listeners to improve scrolling performance
Consider marking your touch and wheel event listeners aspassiveto improve your page’s scroll performance. Learn more.
URL
Location
../wp-includes/js/comment-reply.min.jsjs/comment-reply.min.js(cdn.statically.io)
line: 1Yes I am using statically CDN.
Here is list of code from my CHild theme.
Here is my code for my comments (comments.php:
https://hasteb.in/tubewofa.js
Here is code for my single post (Single.php):
https://hasteb.in/nocotovo.js
Here is my functions.php (theme functions) for which has the shortcode thing for comments:
function display_comment_list() {
ob_start();
global $post;
//print_r($meta);
?>
<?php get_comments();
comments_template();?><?php return ob_get_clean();
}
add_shortcode(‘comment-list’, ‘display_comment_list’);October 14, 2020 at 2:55 am #1488189David
StaffCustomer SupportHi there,
this is a known WordPress ‘bug’ – it is not something that the Theme can fix. Here is one of the more recent CoreTracs raised on the issue:
https://core.trac.wordpress.org/ticket/47510
As you can see a proposed solution has yet to be implemented.
There was one fix found here:
https://stackoverflow.com/a/45974787
But please note the comments as this fix may interfere with other scripts.
January 7, 2021 at 11:13 pm #1610431Charbel
Thank you @David,
Could you please advise how to implement the fix noted on Stackoverflow here? https://stackoverflow.com/a/45974787
I am running GeneratePress with Dispatch Theme. I have a staging site and willing to try it.
Many Thanks!
-CharbelJanuary 7, 2021 at 11:55 pm #1610462Elvin
StaffCustomer SupportHi,
If its about adding the script provided, you can add it in using Code Snippets plugin.
https://wordpress.org/plugins/code-snippets/Add new snippet and place this code in:
add_action( 'wp_footer', function () { ?> <script> (function() { var supportsPassive = eventListenerOptionsSupported(); if (supportsPassive) { var addEvent = EventTarget.prototype.addEventListener; overwriteAddEvent(addEvent); } function overwriteAddEvent(superMethod) { var defaultOptions = { passive: true, capture: false }; EventTarget.prototype.addEventListener = function(type, listener, options) { var usesListenerOptions = typeof options === 'object'; var useCapture = usesListenerOptions ? options.capture : options; options = usesListenerOptions ? options : {}; options.passive = options.passive !== undefined ? options.passive : defaultOptions.passive; options.capture = useCapture !== undefined ? useCapture : defaultOptions.capture; superMethod.call(this, type, listener, options); }; } function eventListenerOptionsSupported() { var supported = false; try { var opts = Object.defineProperty({}, 'passive', { get: function() { supported = true; } }); window.addEventListener("test", null, opts); } catch (e) {} return supported; } })(); </script> <?php } );January 7, 2021 at 11:58 pm #1610466Charbel
Thank you @Elvin, much appreciated for your quick response.
Can I add the code above directly to my function.php Child Theme instead?
January 7, 2021 at 11:58 pm #1610468Elvin
StaffCustomer SupportCan I add the code above directly to my function.php Child Theme instead?
Ah sure you can do that too if you don’t want to use the plugin. 🙂
January 8, 2021 at 12:05 am #1610472Charbel
Thank you so much @Elvin!!!
I used your code and paste it directly in my function.php.
Finally, the warning is gone now from Google PageSpeed Insights 🙂Yesterday, I tried the code noted on Stackoverflow https://stackoverflow.com/a/45974787, however, I got an error when Updating my function.php, it could be a Syntax error.
Many Thanks!!!
January 8, 2021 at 12:25 am #1610483Elvin
StaffCustomer SupportPerhaps you forgot to place it inside a wp_footer hook.
This
add_action( 'wp_footer', ... );line is pretty important.No problem. Glad to be of any help. 😀
January 8, 2021 at 1:19 am #1610528Charbel
Thank you @Elvin,
Yes, the
add_action( 'wp_footer', ... );was missing from Stackoverflow example.All the best,
January 8, 2021 at 1:22 am #1610534Elvin
StaffCustomer SupportNo problem. 🙂
January 11, 2021 at 10:58 am #1614803linuxwolf
Hi Elvin,
Thank you so much. I have used the code directly with the code snippet by pressing the “Add new” button. It is working, although many things to improve.
January 11, 2021 at 9:18 pm #1615192Elvin
StaffCustomer SupportThank you so much. I have used the code directly with the code snippet by pressing the “Add new” button. It is working, although many things to improve.
Nice one. Glad you’re figuring things out. No problem. 😀
March 6, 2021 at 9:10 am #1684670t29k75
Hi Elvin,
If I can ask directly…I used the above snippet in functions.php.
It did the job, except after adding it, Lightbox plugin stopped working.
Could something be changed within the code that it will not affect Lightbox plugin?
thanks,
Tibor
https://surf-atlantic.com/photo-gallery/March 6, 2021 at 5:36 pm #1684988Leo
StaffCustomer SupportHi there,
Just checked the page and lightbox gallery is working for me?
March 6, 2021 at 6:41 pm #1685019t29k75
Hi Leo,
I put that snippet back to functions.php now.
Lightbox Gallery is not working, Any easy fix within the code?
thanks -
AuthorPosts
- You must be logged in to reply to this topic.